Get the real version of IE

Source: Internet
Author: User

IE Browser mode and text mode (ii) published on 2013-09-07Author:jerry Qu

Article Directory

    • Determine the true version of IE
    • JScript engine Version number
    • Does text mode have no effect on JScript?
    • Summarize

Before 1.5 I wrote a "puzzle about browser mode and text mode", which introduced ie8+ 's unique browser mode (Browser mode) and text mode, as well as the discrepancies between my test and Microsoft documentation. There are some things that are not mentioned, and this article continues to discuss.

Determine the true version of IE

Many JS frameworks use UA to determine the version of IE. For IE6, this is not a problem (IE6 does not have the concept of browser mode, and no other IE can change the browser mode to IE6, IE7 Although there is no browser mode, but ie8+ can set the browser mode to IE7 mode). However, the browser mode introduced from IE8 will produce different UA. For example, IE9 has these:

Browser Mode navitor.useragent Default text mode
IE7 MSIE 7.0 IE7 Standard
IE8 MSIE 8.0 && trident/4.0 IE8 Standard
IE9 MSIE 9.0 && trident/5.0 IE9 Standard
IE9 compatibility MSIE 7.0 && trident/5.0 IE7 Standard

If you only judge by "msie x.0" in UA, you will get ie7~9 three different results.

In fact, for ie8+, it is only possible to determine whether the current compatibility view is currently compatible based on the UA string. Because of Compatibility View UA, the IE version and the Trident version do not match. For example, the UA has both "msie 7.0" and "trident/6.0", which indicates that the browser mode is definitely IE10 compatible . This is because IE8 began to add Trident information to UA, and trident/6.0 is unique to IE10.

In addition, the above IE7 and IE8 of the two browser modes, UA and real IE7 or IE8 no difference, according to the UA completely no way to differentiate. Even IE9 mode, we can not confirm whether this is the default mode of IE9 browser, or IE10 browser IE9 mode.

Here's a look at the text pattern, still tested with IE9. Choose a different text pattern, and the value of Documentmode is not the same.

text Mode Document.documentmode
IE7 Standard 7
IE8 Standard 8
IE9 Standard 9
IE5 Weird (Quirks) 5

Document.documentmode This JS attribute is IE8 introduced, for ie8+ no matter what text mode to choose, this property has a value. and IE6 and IE7, this attribute is undefined. According to this, it can be combined with UA to determine whether the user is using a real ie7:ua containing IE7, if documentmode equals undefined, it must be a true IE7 browser. For ie8+, this approach is inadequate. For example IE10 in the browser mode for IE8, text mode for the IE8 standard , compared with the real IE8, whether it is UA, or document.documentmode, are identical.

In conclusion, we can determine whether the browser is working in Compatibility view mode by checking whether the Trident version and the IE version of the UA match. Combined with Document.documentmode, you can also determine whether the user is using a real IE7 browser.

JScript engine Version number

JScript is the JS engine of IE, IE provides a series of JS interfaces to get its JScript information:

function return value
ScriptEngine () JS Fixed return "jscript"
ScriptEngineMajorVersion () Large version number
ScriptEngineMinorVersion () Minor version number
ScriptEngineBuildVersion () Build number

I tested the ie6~10 with these interfaces and found that the version number of JScript was only relevant to the browser, regardless of browser mode or document mode.

Browser JScript Version number
IE6 5.6.8827
IE7 5.7.22145
IE8 5.8.18702
IE9 9.0.16434
IE10 10.0.16521

Ignore the build number, only focus on the first two numbers, we will find that the JS engine from IE9 to Chakra start, the version number of the law changed. Thankfully, different versions of JScript version numbers correspond to different browsers, which is useful for judging the true version of IE. For example, to identify a browser that is below IE8, you can write it down.

?
if(ScriptEngineMinorVersion() != 0 && ScriptEngineMinorVersion < 8) {    //这是 IE8-}

In fact, in the conditional compilation feature supported by IE, there is a conditional compilation variable that represents the version of JScript, as follows (see here for a complete list of conditional compilation variables):

?
<scripttype="text/javascript">    /*@cc_on        alert(@_jscript_version);    @*/</script>

This variable is the JScript version number in the "major.minor" format, consistent with the version number obtained by using the JS interface, and only depends on the browser version, and is not affected by browser mode and text mode.

Does text mode have no effect on JScript?

Read the previous section, and then look at the paragraph I wrote earlier: text mode decision: 1) typesetting engine, 2) JS engine, there are obvious contradictions. Did the previous conclusion be wrong?

In fact, theJScript version number that JS obtains only indicates that the current browser comes with a version of the JScript engine (for example, IE9 always 9.0,ie7 is always 5.7), and does not mean that all the features of this version of the JS engine can be used in any case, the page Which version of the JScript engine to use is still determined by the text pattern of the page .

For example, the JScript version of IE8 is 5.8, but only if the text mode equals the IE8 standard can use the JScript5.8 function, and any other text pattern will cause the page to use JScript5.7.

As an example, JScript5.8 adds support for JSON, so IE8 supports native JSON objects. But many people on the web asked why native JSON could not be used under IE8/9. One possibility is that the page did not write the DTD, causing the page to enter the IE5 weird text pattern, which in turn enabled JScript5.7 that did not support native JSON.

To give a few more examples: [,].length before JScript9.0 was 2;[1,2,3].join (undefined) was "JScript5.8" before 1undefined2undefined3. The IE9 text pattern is changed to IE9 standard ,IE8 standard and IE7 standard respectively, and the following table can be obtained:

text Mode [,].length [1,2,3].join (undefined) version of JScript used
IE7 Standard 2 "1undefined2undefined3" 5.7
IE8 Standard 2 "The" 5.8
IE9 Standard 1 "The" 9.0

There are a lot of similar examples. In most cases, the version of the JScript engine used by the page degrades as the text pattern decreases, and the page's support for JS degrades. But the Guru Franky provides a counter-example of a "for in order":

?
varo = {1 : ‘0‘, 0 : ‘1‘}; for(var i ino) { console.log(i); }

For ie9+ browsers, the output order of this line of code is always 0 1, and for browsers below IE9, the output order is 1 0 and is not affected by text mode. I didn't think of a better explanation for that.

Some DOM-related methods, such as Document.queryselectorall, are not available when the text pattern is IE7 standard ,IE5 is weird , AddEventListener in text mode IE8 Standard ,IE7 standard ,IE5 weird when not available. This means that Internet Explorer's support for DOM also degrades as text patterns degrade.

However, some BOM methods are not related to text mode. For example IE8 started supporting PostMessage and Localstorage, as long as the browser is ie8+, no matter what text mode, these two features are available. Ie9+ supports Window.performance, which is also always available on ie9+ browsers, regardless of the current text mode.

Summary: As the text pattern decreases, the JScript engine that is actually used on the page degrades, and some of the language features that are supported by the high version are no longer available (such as JSON), but the in order problem does not seem to degenerate, and the DOM-related functionality is degraded, but most BOM interfaces do not degrade (such as Localstorage).

Summarize

The content discussed in this paper has been summarized in each part, and finally only one conclusion: in solving the JS compatibility problem, we must use ability detection and feature detection. Because neither the browser information obtained from UA nor the version of the JScript engine obtained from the JS interface is very reliable. For example, the UA contains IE7 and does not necessarily support ie9+ 's window.performace. It is also possible that the IE9 browser uses the IE9 compatibility View , the UA does become IE7, the text pattern is IE7 standard , but does not affect the support for window.performace.

In addition, although the browser mode and text mode of IE are very complex, there are dozens of cases in combination, but most of them can only be constructed by developer tools. For example, the UA contains IE9, in fact the case of using JScript5.7 (browser mode is IE9, text mode is IE7 standard ), normally does not appear.

Reference:

    • How Internet Explorer 8 Document mode affects JavaScript
    • Same Markup:explaining "@_jscript_version" and styling New HTML5 Elements
    • Versioning Language Features in JScript
    • IE9 characteristic change by Franky

This article link: https://www.imququ.com/post/browser-mode-and-document-mode-in-ie-2.html

Get the real IE version (GO)

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.