The main reason to judge IE version is to get two properties,a. Current browser name ,B. The current browser version , so you have to understand the Navigator object.
Post Code First
1Window.onload =function () {2 varBrowser_name = Navigator.appname,//gets the name of the current browser3Browser_version = Navigator.appversion,//get platform and version information for the current browser4Version_arr = Browser_version.split (";"),//to follow the platform version information; cut an array5Version = version_arr[1].replace (/\s/g,"");//take the element labeled 1 in the previous step array, go to space6 //Console.log (browser_name);7 //Console.log (browser_version);8 //Console.log (Version_arr);9 //Console.log (version);Ten One if(Browser_name = ="Microsoft Internet Explorer") {//if the browser name is IE A if(Version = ="MSIE5.0"|| Version = ="MSIE7.0") {//the current version of IE satisfies either of them to perform the following actions - -Alert"For a better experience, please download the latest browser"); the } - } -};
As a first-time understanding of the Navigator object, for the appname property (browser name), your intuitive feeling may be that using Google Browser is Chrome, using the QQ browser to get the name is Qqbrowser, but unfortunately, Currently, there are only two values obtained for AppName, one is "Netscape" (Netscape) and the other is "Microsoft Internet Explorer" (IE).
In the current browser such as Google, 360,qq Browser, Sogou, IE11, etc., get appname are Netscape, according to W3school instructions, the move is convenient for compatibility between browsers, But for the history of the Internet to understand people know that Netscape for the development of the Internet to make a contribution, so for some netizens said, this is also out of the Netscape of the memory of the meaning also quite reasonable.
including IE10 and the lower version of IE,appname Get the value are Microsoft Internet Explorer, If you have IE11 installed on your PC, press F12 to bring up the console, Simulation results can be used to simulate the actual situation of various versions of IE:
We can look at the default IE11 and IE10 partial version of the AppName value case
IE11 AppName Value
IE10 AppName Value
IE5 AppName Value
As you can see, versions of IE version less than 11, appname properties are Microsoft Internet Explorer. (say Netscape is because IE is down, the result is now IE in order to be compatible, appname incredibly also for Netscape ...)
Finally, simply say navigator's appversion gets the version number attribute, generally uses IE10 and the following version , obtains the value to be like this
including IE8,IE7 and other low versions, the version information format is, so in the acquisition version of the method used by split (";") To cut, get the elements of subscript 1 to determine the version.
However, it should be noted thatIE11 and the current mainstream browser version Information format is not the same , so different browser specific crawl method according to the actual situation to judge. such as Google's version information
Probably write so much, my first blog article.
"A small function" judging ie version from JS, talking about the AppName property of navigator Object