This article mainly introduces the Internet Explorer 11 browser introduction: Don’t call me IE, friends in need can refer to it.
Last week, Microsoft officially launched the first preview version of Internet Explorer 11 with Windows 8.1. With that, it’s time to put the various rumors about leaked versions of this controversial web browser to rest. We now know some important details about Internet Explorer 11, including support for WebGL, prefetch, prerender, flexbox, mutation observers and other web standards, perhaps more interestingly in IE11, is that it's not IE.
For the first time in a long time, Microsoft has removed some features from the Internet Explorer browser. The user-agent string has also changed. It seems that Microsoft has abandoned its own approach, so that the existing code branch that detects IE will return false in the Internet Explorer 11 browser, whether in javascript or on the server.
User-agent changes
Compared with previous versions, Internet Explorer 11’s user-agent string is shorter, and there are some interesting changes:
Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko
For the user-agent string of Internet Explorer 10 on Windows 7
Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)
The most obvious difference is that, all the time The "MSIE" tag present in the Internet Explorer user-agent string has been removed. Also noticeable is the addition of "like Gecko" at the end of user-agent. This suggests that Internet Explorer would rather be identified as the Gecko browser than Internet Explorer itself. Safari was the first browser to add "like Gecko" so that anyone could sniff the "Gecko" characters in the user-agent string and allow the browser to pass.
Now any sniffing code looking for "MSIE" will not work under the new user-agent string. You can still search for "Trident" characters to make sure it's IE (the "Trident" logo was introduced with Internet Explorer). The true version of Internet Explorer is identified by "rv".
In addition, the information of the navigator object has also been changed, which further conceals the browser being used.
navigator.appName is set to "Netscape"
navigator.product is set to "Gecko"
This may look like a sneaky attempt to trick developers, but these are actually HTML5 specified. The navigator.product attribute must be "Gecko", and the navigator.appName should also be "Netscape" or more specific. But Internet Explorer 11 fails to follow this strange advice.
As a side effect of the change in navigator information, the browser detection based on Javascript logic in use may not be available, causing Internet Explorer 11 to be recognized as a Gecko-based browser.
document.all and his friends
Since IE4, document.all is omnipotent in IE browser. Similar to the previously implemented document.getElementById(), document.all is the IE method of getting a reference to a DOM element. Although from IE5 to IE10, document.all maintains support for the DOM. However, in 11, the legacy of this era has been set to return false, which means that any code branch judgment based on document.all will fail in IE11, even if the code actually uses document.all and works normally.
Another legacy is to add the attachEvent() of the event function, similar to the detachEvent() method. This method has been removed from IE11. These methods are removed to avoid some logical judgments, such as:
function addEvent(element, type, handler) { if (element.attachEvent) { element.attachEvent("on" + type, handler); } else if (element.addEventListener) { element.addEventListener(type, handler, false); } }
Of course, we recommend that the best version for you to test is one that is always stable and meets standards. At some level, removing the attachEvent method won't cause any discomfort. However, the Internet is littered with poor feature detection logic code. The removal of the attachEvent method ensures that any code written in the above manner will use the standard version instead of the IE-specific method.
Some other removed features:
window.execScript() - the IE version of the eval() method
window.doScroll() - the IE version of the window Scroll method
script.onreadystatechange - Monitor the status change of the loaded script in IE
script.readyState - The status of script loading in IE
document.selection - IE The currently selected text in
document.createStyleSheet - Create a style sheet document in IE
style.styleSheet - A style object that references a style sheet in IE browser
All these IE browser ways have been replaced by standard features. After removing these features and methods, cross-browser code based on standard functional feature detection can still run normally without changes.
Conclusion
In a long time, IE11 may be the best IE browser. Microsoft is finally getting ready to undo the mistakes of the past and is starting to include a browser based on today's standards. Removing old features and modifying user agent strings that are not recognized by IE is a unique approach that ensures that all sites will continue to work. If the web application uses feature detection instead of browser sniffing, the code should run in IE11. For applications that use user-agent sniffing, users can still see a fully functional website because IE11 has excellent standards support.
A future without IE branch code is coming soon, let us look forward to it together.
(updated on 2013-7-2), the document.all mentioned in the revision was not actually deleted, but changed to falsy
The above is the entire content of this chapter. For more related tutorials, please Visit JavaScript Video Tutorial!