The shortest ie judgment method, the original address: http://www.jb51.net/article/23621.htm
The shortest way to judge IE Browser:var Isie =!-[1,]
Principle: [1,] return "1" in standard browser, equivalent to call [1,].tostring (), return "1" in IE.
When the return value is cast to a number at this time, the standard browser returns 1,ie and returns Nan.
When the 1 and Nan are reversed, the standard browser returns False,ie returns TRUE.
JS to determine the browser type
The original text is basically no problem, but his way of judging is not very rigorous.
such as: Navigator.userAgent.indexOf ("Safari") >0, if the word "Safari" appears in the forefront of useragent, it is not impossible to get the correct results. The >0 should be changed to!=-1.
Then I tested the existing 5 standalone kernel browsers on my machine and found that Opera's useragent value was "opera/9.80" (Windows NT 5.1; U Ed ... "
It just confirms what I said.
In fact, most of the time when we do browser compatibility is mainly for IE and non-ie browsers, that is, generally speaking, only to determine whether IE browser can.
To determine the current browser type code
Copy Code code as follows:
<script type= "Text/javascript" >
<!--
function Getos ()
{
var osobject = "";
if (Isie = navigator.userAgent.indexOf ("MSIE")!=-1) {
return "MSIE";
}
if (Isfirefox=navigator.useragent.indexof ("Firefox")!=-1) {
return "Firefox";
}
if (Ischrome=navigator.useragent.indexof ("Chrome")!=-1) {
return "Chrome";
}
if (Issafari=navigator.useragent.indexof ("Safari")!=-1) {
return "Safari";
}
if (Isopera=navigator.useragent.indexof ("Opera")!=-1) {
return "Opera";
}
}
Alert ("Type->" +getos ());
-->
</script>