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.