Summary of js/jquery methods for determining browser types, jsjquery

Source: Internet
Author: User

Summary of js/jquery methods for determining browser types, jsjquery

JS to get browser Information

Copy codeThe Code is as follows:
Browser code name: navigator. appCodeName
Browser name: navigator. appName
Browser version: navigator. appVersion
Java support: navigator. javaEnabled ()
MIME Type (array): navigator. mimeTypes
System platform: navigator. platform
Plug-in (array): navigator. plugins
User Agent: navigator. userAgent

Js:

Method 1:

If (window. addEventListener) {alert ("not ie");} else if (window. attachEvent) {alert ("is ie");} else {alert ("this happens when browsers of earlier versions that do not support DHTML are generally supported now )")}

Note: The not IE result is displayed in ie 9 or later.

Method 2:

if(document.all){ alert("IE"); }else{ alert("not ie"); }

Method 3:

var navigatorName = "Microsoft Internet Explorer"; if( navigator.appName == navigatorName ){ alert("ie") }else{alert("not ie") }

Method 4:
The difference between IE and the standard browser in handling the toString method of the array is used. For the standard browser, if the last character in the array is a comma, The JS engine will automatically remove it.

If (! + [1,]) alert ("this is Internet Explorer"); else alert ("this is not Internet Explorer ");

Note: "This is not an IE browser" will pop up in IE9 and later versions"

Methods to determine common browsers:

var explorer =navigator.userAgent ;//ie if (explorer.indexOf("MSIE") >= 0) {alert("ie");}//firefox else if (explorer.indexOf("Firefox") >= 0) {alert("Firefox");}//Chromeelse if(explorer.indexOf("Chrome") >= 0){alert("Chrome");}//Operaelse if(explorer.indexOf("Opera") >= 0){alert("Opera");}//Safarielse if(explorer.indexOf("Safari") >= 0){alert("Safari");} //Netscapeelse if(explorer.indexOf("Netscape")>= 0) { alert('Netscape'); } 

Here, navigator. userAgent. indexOf ("MSIE")> = 0 is used for determination. Of course, you can also use
Navigator. userAgent. indexOf ("MSIE ")! =-1.

How does jquery determine the browser type and version number?

$(document).ready(function(){  var brow=$.browser;  var bInfo="";  if(brow.msie){bInfo="MicrosoftInternetExplorer"+brow.version;}  if(brow.mozilla){bInfo="MozillaFirefox"+brow.version;}  if(brow.safari){bInfo="AppleSafari"+brow.version;}  if(brow.opera){bInfo="Opera"+brow.version;}  alert(bInfo);});

Note: The. browser and. browser. version are removed from Query 1.9 and replaced with the $. support method.

The above is all the content of this article. I hope you will like it.

Related Article

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.