Go to http://www.51obj.cn /? P = 368
I used to check the navigator. useragent string to determine the browser type.
Switch (navigator. useragent. tolowercase (). indexof ("MSIE") // Firefox | opera | safari | MSIE
{
Case (-1 ):
Alert ("dom Browser ");
Default:
Alert ("IE browser ");
}
F
Today, I read an article about how users can change the useragent in Some browsers, so that they cannot simply use this method to check the browser. In actual use, the difference between IE browser and standard DOM browser is checked most often. In this way, you can use window. addeventlistener to judge the two types of browsers.
If (typeof window. addeventlistener = "function "){
Alert ("dom Browser ");
} Else {
Alert ("ie ");
}
Code of a browser with high handwriting
VaR isie = !! (Window. attachevent &&! Window. Opera );
VaR isopera = !! Window. Opera;
VaR issafari = navigator. useragent. indexof ('applewebkit/')>-1;
VaR ismoz = navigator. useragent. indexof ('gecko ')>-1 & navigator. useragent. indexof ('khtml') =-1;
VaR ismobilesafari = !! Navigator. useragent. Match (/Apple. * mobile. * Safari /);
VaR isie5 = (navigator. appversion. indexof ("MSIE 5")> 0) | (navigator. appversion. indexof ("MSIE")> 0 & parseint (navigator. appversion)> 4 );
VaR isie55 = (navigator. appversion. indexof ("MSIE 5.5")> 0 );
VaR isie6 = (navigator. appversion. indexof ("MSIE 6")> 0 );
VaR isie7 = (navigator. appversion. indexof ("MSIE 7")> 0 );
VaR isie8 = (navigator. appversion. indexof ("MSIE 8")> 0 );