Js quick judgment on IE browsers (compatible with IE10 and IE11)

Source: Internet
Author: User

In many cases, we generally use navigator. userAgent and regular expression are used to determine the version of IE browser. The following describes how to use different features in IE browser to Determine IE browser 1. The difference between IE browser and IE browser is that IE browser supports ActiveXObject, however, non-ie Browsers Do not support ActiveXObject. When the IE11 browser hasn't appeared, we can determine that the 123 function isIe () {return window. ActiveXObject is often written in IE and non-IE? True: false;} but in IE11, the returned value is false. I tested the following code in IE11: alert (window. activeXObject); alert (typeof window. activeXObject); the result is image. Why? Obviously, ActiveXObject exists, and the result of typeof is indeed undefined. Who knows the result and tells me why? Why? On the official website of Microsoft, the ActiveXObject of IE11 is different. Http://msdn.microsoft.com/en-us/library/ie/dn42394820.28v?vs.85=29.aspx. However, the reason for typeof is not explained. If we use the following code to detect alert ("ActiveXObject" in window) // false is returned in ie11. I don't understand this. "ActiveXObject" in window returns true. Why did I judge that the IE browser code returned in IE11 is false? Ask the experts for an explanation again. Thank you. The following describes how to determine whether the Internet Explorer and Internet Explorer are compatible with Internet Explorer 11. Function isIe () {return ("ActiveXObject" in window);} note that the precondition is that ActiveXObject should not be overwritten in our program code. No program should do this. Haha. 2. It is determined that IE supports XMLHttpRequest objects from IE7, but IE6 does not. Based on this feature and the previous function isIe () of IE, we will know how to judge IE6. The determination method is as follows: function isIe6 () {// ie6 does not support return isIe () of window. XMLHttpRequest ()&&! Window. XMLHttpRequest;} 3. ie7page views are supported by document.doc umentMode because they are supported in the document format starting from ie8. IE7 is not supported, but IE7 supports XMLHttpRequest objects. The determination method is as follows: function isIe7 () {// only ie8workflow supports document.doc umentMode return isIe () & window. XMLHttpRequest &&! Document.doc umentMode;} 4 judge that the IE 8 browser is gradually approaching the standard from IE9. We call IE678 a non-standard browser, and IE9 + and other browsers such as chrome. firefox is called a standard browser. One of the differences is. You can test the following code. What is returned alert (-[1,]); // print NaN in IE678, but the standard browser prints "-1", so we can judge that it is the IE8 browser based on the above difference. Function isIe8 () {// alert (! -[1,]) //-> IE678 returns NaN! If NaN is true, the standard browser returns-1, so! -1 is false return isIe ()&&! -Example 1, example &document.doc umentMode;} 5 judge that IE9, IE10, and IE11 browsers support JSON built-in objects in IE8 browsers, and IE10 supports strict js mode, for the strict mode in JS please refer to this article http://www.ruanyifeng.com/blog/2013/01/javascript_strict_mode.html IE9 + under alert (! -[1,]) the returned value is false. IE9 + supports addEventListener, but the unique events in IE cannot be bound to attachEvent in IE11. Based on these differences, we can differentiate IE9, IE10, and IE11 browsers. 6. Verify that other browsers copy the code/*** from the public class functions encapsulated in the previous project *** // check the function var check = function (r) {return r. test (navigator. userAgent. toLowerCase () ;}; var statics ={/ *** whether it is a webkit kernel browser */isWebkit: function () {return check (/webkit /);}, /*** is firefox browser */isFirefox: function () {return check (/firefox/);},/*** is it Google browser */isChrome: function () {return! Statics. isOpera () & check (/chrome/) ;},/*** whether it is an operabrowser */isOpera: function () {return check (/opr /);}, /*** check if it is a Safari browser */isSafari: function () {// safari return is also included in google chrome! Statics. isChrome ()&&! Statics. isOpera () & check (/safari /);}};

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.