JavaScript to judge the access terminal

Source: Internet
Author: User

最近制作了一个二维码,在android平台会进去android下载渠道,如果是ios系统,则进去appStore下载,代码如下

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>Title</title>
<body style= "font-size:40px;" >
<div id= "Tips" style= "padding:50px 0;width:100%;margin:0 auto;display:none;" >

</div>

</body>
<script type= "Text/javascript" >
Judging the access terminal
var browser={
Versions:function () {
var u = navigator.useragent, app = Navigator.appversion;
return {
Trident:u.indexof (' Trident ') >-1,//ie core
Presto:u.indexof (' presto ') >-1,//opera core
Webkit:u.indexof (' AppleWebKit ') >-1,//Apple, Google kernel
Gecko:u.indexof (' Gecko ') >-1 && u.indexof (' khtml ') = = -1,//Firefox kernel
Mobile:!! U.match (/applewebkit.*mobile.*/),//Whether it is a mobile terminal
Ios:!! U.match (/\ (i[^;] +;( U;)? Cpu.+mac OS x/),//ios terminal
Android:u.indexof (' Android ') >-1 | | U.indexof (' Adr ') >-1,//android terminal
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 with bottom
Weixin:u.indexof (' Micromessenger ') >-1,//whether (added 2015-01-22)
Qq:u.match (/\sqq/i) = = "QQ"//whether QQ
};
}(),
Language: (Navigator.browserlanguage | | navigator.language). toLowerCase ()
};

if (!browser.versions.mobile) {

If not mobile scan QR code
Alert ("Please scan the QR code with your phone");
}else if (browser.versions.android) {

If Android, go directly to the download link
location.href= ' http://url.cn/42G7PNz ';
}
else if (browser.versions.weixin && (Browser.versions.ios | | browser.versions.iPad)) {

If it is an iOS system and is turned on, a reminder is displayed (direct jump AppStore not supported)
document.getElementById ("Tips"). Style.display = "block";
}else if (Browser.versions.ios | | browser.versions.iPad) {

If it is an iOS system and is not open in, jump directly to AppStore
location.href= ' https://itunes.apple.com/cn/app/sui-shi-bao/id1097442883?mt=8 ';
}
</script>

 最后用二维码生成器,把此页面生成二维码即可

JavaScript to judge the access terminal

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.