How to use JS to identify different browsers

Source: Internet
Author: User

If you want to test the characteristics of a browser, you can obtain the following methods

JS Get browser information
Browser code Name: Navigator.appcodename
Browser name: Navigator.appname
Browser version number: Navigator.appversion
Support for Java: navigator.javaenabled ()
MIME type (array): Navigator.mimetypes
System platform: Navigator.platform
Plugin (array): Navigator.plugins
User agent: Navigator.useragent

Compare the whole

1<script type= "Text/javascript" >2document.write (' Browser award: ');3 varosobject=navigator.useragent;4 //contains "opera" text columns5 if(Osobject.indexof ("Opera")! =-1) 6 { 7document.write (' Your browser is opera? ‘); 8 } 9 //contains "msie" text columnsTen Else if(Osobject.indexof ("MSIE")! =-1)  One {  Adocument.write (' Your browser is Internet Explorer? ‘);  - }  - //contains "chrome" text columns, but 360 browsers also copy Chrome's UA the   - Else if(Osobject.indexof ("Chrome")! =-1)  - {  -document.write (' Your browser is chrome or 360 browser? ‘);  + } - //contains "ucbrowser" text columns + Else if(Osobject.indexof ("Ubrowser")! =-1)  A {  atdocument.write (' Your browser is Ubrowser? ‘);  - } - //contains "bidubrowser" text columns - Else if(Osobject.indexof ("Bidubrowser")! =-1)  - {  -document.write (' Your browser is Baidu browser bar? ‘);  in } - //contains "firefox" text columns to Else if(Osobject.indexof ("Firefox")! =-1)  + {  -document.write (' Your browser is Firefox? ‘);  the } * //contains "netscape" text columns $ Else if(Osobject.indexof ("Netscape")! =-1)Panax Notoginseng {  -document.write (' Your browser is Netscape? ‘);  the }  + //contains "safari" text columns A Else if(Osobject.indexof ("Safari")! =-1)  the {  +document.write (' Your browser is safari? ‘);  - }  $ Else{  $document.write (' Unrecognized browser. ‘);  - }  -</script>

How to use JS to identify different browsers

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.