How to check the browser type

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.