The changed information is as follows:
IE8 on Windows Vista (Compatibility View) Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/4.0) IE8 on Windows vistamozilla/4.0 (compatible; MSIE 8.0; windows NT 6.0; Trident/4.0)
In addition to the Compatibility View function, IE8 also becomes very interesting in addition to multiple "native" user-agents in a single browser, that is, almost every browser adds the rendering engine identifier to the User-Agent (Gecko, WebKit, and Trident ).
User-Agent information is often used as the best way to detect browser types and versions (Yui, jquery). Does the above change mean that similar detection scripts will become more complex in the future? Before answering this question, let's take a look at how mootools detects browser information.
VaR browser = {Engine: {Name: 'unknown ', version: 0}, features: {XPath :!! (Document. Evaluate), // whether xpathair:! Is supported :!! (Window. runtime), // whether the query extension of air is supported :!! (Document. queryselector) // whether the CSS selector is supported}, engines: {// determine operapresto: function () {return (! Window. Opera )? False: (arguments. callee. Caller )? 960: (document. getelementsbyclassname )? 950: 925) ;}, // judge IE, according to ActiveX and the unique XMLHTTPRequest object Trident: function () {return (! Window. activexobject )? False: (window. XMLHttpRequest )? 5: 4) ;}, // WebKit core browsers, such as safari and chromewebkit: function () {return (navigator. taintenabled )? False: (browser. features. XPath )? (Browser. features. query )? 525: 420): 419) ;}, // Mozilla Gecko core browser, such as firefoxgecko: function () {return (document. getboxobjectfor = undefined )? False: (document. getelementsbyclassname )? 19: 18) ;}}}; browser. detect = function () {for (VAR engine in this. engines) {var version = This. engines [engine] (); // If the browser object if (Version) {This. engine = {Name: Engine, version: Version}; this. engine [engine] = This. engine [engine + version] = true; break ;}return {Name: Engine, version: Version };}; browser. detect ();
AboveCodeIt is refreshing. It determines the browser type based on the browser function rather than the User-Agent. After careful consideration, the User-Agent information can be forged and the browser vendor will change the User-Agent information in the future. Therefore, it is much more reliable to judge the browser type based on the function.
Extend this policy. For example, we will write such code:
If (IE) {// ie only} else {// other browsers}
In this way, the "hard code" written due to browser differences often lead to the maintenance of two sets of codes with the same functions and logical confusion. Why not ignore the browser compatibility problem and then judge whether the corresponding object is supported by the browser.
Okay. I will not continue with the issues related to programming ideas...
-- Split --
PS. You can write this code to determine whether it is IE8.
VaR isie8 = !! Window. xdomainrequest;