Among many browser products, IE, Firefox, Opera, Safari ........ many brands have different standards. Therefore, you often need to perform different operations based on different browsers or even different versions of the same browser. Therefore, it is very important to know the browser's judgment method. The following lists common judgment methods.
1. Determine whether the browser is IE
Document. all? 'Ie': 'others ': the document. all value in IE is 1, and the value in other browsers is 0;
Navigator. userAgent. indexOf ("MSIE")> 0? 'Ie': 'others ': navigator. userAgent indicates the user agent information.
Navigator. appName. indexOf ("Microsoft ")! =-1? 'Ie': 'others ': navigator. appName indicates the browser name.
2. Determine the IE version
Navigator. appVersion. match (/6./I) = "6 ."? 'Ie6': 'Other version': This method can be used to determine whether IE6 is an Internet Explorer;
Navigator. userAgent. indexOf ("MSIE 6.0")> 0? 'Ie7': 'Other version': Same as above;
Navigator. appVersion. match (/7./I) = "7 ."? 'Ie7': 'Other version': This method can be used to determine whether IE7 is a known Internet Explorer;
Navigator. userAgent. indexOf ("MSIE 7.0")> 0? 'Ie7': 'Other version': Same as above;
Navigator. appVersion. match (/8./I) = "8 ."? 'Ie8': 'Other version': This method can be used to determine whether the Internet Explorer is IE8;
Navigator. userAgent. indexOf ("MSIE 8.0")> 0? 'Ie8': 'Other version': Same as above.
3. JS obtains browser Information
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
DEMO:
Js Code
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]