JS to determine whether it is IE browser and give the IE version

Source: Internet
Author: User
Tags key string

Before too lazy to write judgment ie version js, because the online about this aspect of the code too much, so from the online copy of a, put on the project only to find due to the issue of timeliness, the code does not take effect. Just write one yourself.

    1. How to see the browser's kernel and other information----JS Global Object Window Sub-property navigator.useragent, this property contains information about the browser information, including the browser kernel we need
    2. Navigator.useragent This value is a string that can be validated by the string's IndexOf method or regular match to validate the key string
    3. Ie11 and Edge are judged differently, and I'll give you a few figures later
    4. This is Ie11 's useragent.
    5. This is edge useragent.
    6. IE9 's useragent
    7. IE8 's useragent
    8. Ie10 's useragent

You must have found that the ie11 and edge of the useragent is very big difference with ie8,9,10, then the use of the writing JS need to judge, the following gives me to write a section of the judgment is IE and give the IE version number of JS code snippet

        function ieversion () {var useragent = navigator.useragent;//Get the useragent string of the browser var Isie = Useragent.indexof ("compatible") >-1 && useragent.indexof ("MSIE") >-1; Determine if ie<11 browser var Isedge = useragent.indexof ("Edge") >-1 &&!isie; Determine if IE's Edge browser var isIE11 = useragent.indexof (' Trident ') >-1 && useragent.indexof ("rv:11.0") &G T            -1;                if (Isie) {var reie = new RegExp ("MSIE (\\d+\\.\\d+);");                Reie.test (useragent);                var fieversion = parsefloat (regexp["$"]);                if (fieversion = = 7) {return 7;                } else if (fieversion = = 8) {return 8;                } else if (fieversion = = 9) {return 9;                } else if (fieversion = =) {return 10; } else {return 6;//ie version <=7}} elSe if (isedge) {return ' Edge ';//edge} else if (isIE11) {return one;//ie11 }else{return-1;//not IE browser}}

The return value can be obtained by calling Ieversion (), with the following values

Value Value type Value Description
-1 Number Not IE browser
6 Number IE version <=6
7 Number Ie7
8 Number Ie8
9 Number Ie9
10 Number Ie10
11 Number Ie11
' Edge ' String IE's Edge browser

JS to determine whether it is IE browser and give the IE version

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.