Original address:http://blog.csdn.net/wy978651775/article/details/9014039 The blogger is also reproduced, but did not indicate the source.
The principle of judgment: JavaScript is the main language of the front-end development, we can write JavaScript program to determine the type and version of the browser. JavaScript generally has two ways of judging browser types, one is based on the unique attributes of various browsers, and the other is judged by analyzing the browser's useragent properties. In many cases, after the value of the browser type is determined, you also need to determine the browser version to handle compatibility issues, and the browser version can only be determined by analyzing the browser useragent to know. Browser type ⑴ browser-specific properties ⑵ according to the UserAgent browser version ⑴ according to the useragent for mobile browser judgment 1. How to determine if a regular match is used for a mobile terminal, Matches whether navigator.useragent contains strings applewebkit*****mobile android QQ browser HD version only AppleWebKit2 phone language version of the decision to use Navigator.browserlanguage Can be found in the Windows Phone language version, of course, the hateful small phone language version also has compatibility differences, compatible with Mozilla, and the AppleWebKit kernel browser to access its language version, it will list Navigator.languagecode: <script type= "Text/javascript" > var browser={versions:function () {var u = navigator.useragent, app = navigator.appversion; return {//Mobile terminal browser version information Trident:u.indexof (' Trident ') >-1,//ie kernel Presto:u.inde XOf (' Presto ') >-1,//opera kernel webkit:u.indexof (' AppleWebKit ') >-1,//Apple, Google kernel Gecko: U.indexof (' Gecko ') >-1 && u.indexof (' khtml ') = =-1,//Firefox core mobile:!! U.Match (/applewebkit.*mobile.*/),//Whether for Mobile terminal iOS:!! U.match (/(i[^;] +;( U;)? Cpu.+mac OS x/),//ios terminal Android:u.indexof (' Android ') >-1 | | U.indexof (' Linux ') >-1,//android terminal or UC Browser iphone:u.indexof (' iphone ') >-1,//whether for IPhone or Qqhd browser Ipad:u.indexof (' ipad ') >-1,//whether IPad webapp:u.indexof (' Safari ') = = 1//Whether the Web should be program, no head and bottom department}; } (), Language: (Navigator.browserlanguage | | navigator.language). toLowerCase ()} document.writeln ("language version:" +browser.language);d Ocument.writeln ("is mobile Terminal:" + Browser.versions.mobile);d Ocument.writeln ("iOS terminal:" +browser.versions.ios);d Ocument.writeln ("Android Terminal:" + browser.versions.android);d Ocument.writeln ("is IPhone:" +browser.versions.iphone);d Ocument.writeln ("Whether ipad:" + BROWSER.VERSIONS.IPAD);d Ocument.writeln (navigator.useragent); </script> Compare special place UC Browser without Android header, only return: Linux, here roughly based on Linux to judge is Android (premise must meet is mobile terminal, UC This is satisfied) The result of Android QQ browser HD version is: Mac, Safari
JS to determine whether Android Access or iOS access