JavaScript code used to determine the browser type and version

Source: Internet
Author: User

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]

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.