Home  >  Article  >  Web Front-end  >  JS implementation code to determine browser type and version_javascript skills

JS implementation code to determine browser type and version_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:49:18952browse

Among the many browser products, IE, Firefox, Opera, Safari... many brands have different standards, so it is often necessary to perform different operations based on different browsers, or even different versions of the same browser. Therefore, it is still important to know the browser's judgment method. Listed below are commonly used judgment methods

1. Determine whether the browser is IE

document.all ? 'IE' : 'others': under IE, the document.all value is 1, and The value under other browsers is 0;
navigator.userAgent.indexOf("MSIE")>0 ? 'IE' : 'others': navigator.userAgent describes user agent information.
navigator.appName.indexOf("Microsoft") != -1 ? 'IE' : 'others': navigator.appName describes browser name information.

2. Determine the IE version

navigator.appVersion.match(/6./i)=="6." ? 'IE6' : 'other version': It is known to be IE In the case of a browser, you can use this method to determine whether it is IE6;
navigator.userAgent.indexOf("MSIE 6.0")>0 ? 'IE7' : 'other version': Same as above;
navigator.appVersion .match(/7./i)=="7." ? 'IE7' : 'other version': When the browser is known to be IE, this method can be used to determine whether it is IE7;
navigator. userAgent.indexOf("MSIE 7.0")>0 ? 'IE7' : 'other version': Same as above;
navigator.appVersion.match(/8./i)=="8." ? 'IE8' : 'other version': When the browser is known to be IE, you can use this method to determine whether it is IE8;
navigator.userAgent.indexOf("MSIE 8.0")>0 ? 'IE8' : 'other version ': Same as above.

3. JS gets browser information

Browser code name: navigator.appCodeName
Browser name: navigator.appName
Browser version number: navigator.appVersion
Support for Java: navigator.javaEnabled()
MIME types (array): navigator.mimeTypes
System platform: navigator.platform
Plugins (array): navigator.plugins
User agent: navigator .userAgent

DEMO:
Js code


[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn