JS Judge Mobile browser (turn)

Source: Internet
Author: User

Reprint Address: http://www.cnblogs.com/phphuaibei/archive/2011/12/09/2282570.html

Principle of judgment:

JavaScript is the primary language for front-end development, and we can write JavaScript programs 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 UserAgent

Browser version

⑴ according to UserAgent

for mobile browser judgment

1. How to determine whether to use regular match for mobile terminals,

Matches whether the navigator.useragent contains a string applewebkit*****mobile

Android QQ Browser HD version only AppleWebKit

2 Phone language version of the judgment

Use navigator.browserlanguage to derive the Windows Phone language version,
Of course, hateful little mobile language versions also have compatibility differences, compatible with Mozilla, and the AppleWebKit kernel browser to access its language version, which will list Navigator.language

1234567891011121314151617181920212223242526272829303132 <script type="text/javascript">/** 智能机浏览器版本信息:**/  var browser={    versions:function(){            var u = navigator.userAgent, app = navigator.appVersion;            return {//移动终端浏览器版本信息                 trident: u.indexOf(‘Trident‘) > -1, //IE内核                presto: u.indexOf(‘Presto‘) > -1, //opera内核                webKit: u.indexOf(‘AppleWebKit‘) > -1, //苹果、谷歌内核                gecko: u.indexOf(‘Gecko‘) > -1 && u.indexOf(‘KHTML‘) == -1, //火狐内核                mobile: !!u.match(/AppleWebKit.*Mobile.*/)||!!u.match(/AppleWebKit/), //是否为移动终端                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端                android: u.indexOf(‘Android‘) > -1 || u.indexOf(‘Linux‘) > -1, //android终端或者uc浏览器                iPhone: u.indexOf(‘iPhone‘) > -1 || u.indexOf(‘Mac‘) > -1, //是否为iPhone或者QQHD浏览器                iPad: u.indexOf(‘iPad‘) > -1, //是否iPad                webApp: u.indexOf(‘Safari‘) == -1 //是否web应该程序,没有头部与底部            };         }(),         language:(navigator.browserLanguage || navigator.language).toLowerCase()} document.writeln("语言版本: "+browser.language);document.writeln(" 是否为移动终端: "+browser.versions.mobile);document.writeln(" ios终端: "+browser.versions.ios);document.writeln(" android终端: "+browser.versions.android);document.writeln(" 是否为iPhone: "+browser.versions.iPhone);document.writeln(" 是否iPad: "+browser.versions.iPad);document.writeln(navigator.userAgent);</script>

More special places.

UC Browser does not have an Android header, only return: Linux, here is roughly based on Linux to determine that Android (the premise must be satisfied with the mobile terminal, UC this is satisfied)

Android QQ browser HD test results are: Mac, Safari, this is a pervert, you look at the process of it

3 Web sites that detect browser user-agent information


Three online web sites can be detected online via a mobile browser, which is convenient

1. http://whatsmyuseragent.com/

2. http://whatsmyua.com/

3. http://www.useragentstring.com/

Reference article:

PC Browser

Http://www.jb51.net/article/17302.htm

Http://www.bairuiw.com/front-end-skill/1346.html

Mobile browser

Http://www.iundefined.com/development/344.html

Http://www.cnblogs.com/dowinning/archive/2011/07/22/2113747.html

Http://www.cnblogs.com/dowinning/archive/2011/07/22/2113981.html

Http://luckerme.com/archives/1015.html

JS Judge Mobile browser (turn)

Related Article

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.