欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
您的位置:DIVCSS5首页 > HTML >

在移动wap上,最常见的就是引流用户下载安装自己的应用程序,如何通过js点击判断下载是ios还是安卓呢?其实很简单,就是要判断用户的设备是iOS还是Android,然后分别跳转就可以了。

<script type="text/javascript">

var u = navigator.userAgent;

var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端

var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端

alert('是否是Android'+isAndroid);

alert('是否是iOS'+isiOS);

</script>

有了这个判断,就可以根据对应的平台来进行操作。

 

1.安卓的,就直接下载app,或者跳到安卓应用市场下载

 

2.iOS的,直接跳到苹果商店的应用页进行下载

 

3.其它平台,跳到自定义的页面,比如一个放有多个平台的下载页。

function downApp(){

       var u = navigator.userAgent,

       isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1,

       isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),

       urls = {

              'android':'http://ftp-apk.pcauto.com.cn/pub/autoclub-5000-autowapDL1.apk',

              'ios':'https://itunes.apple.com/cn/app/zhong-guo-che-you-hui/id640447959',

              'other':'http://www1.pcauto.com.cn/app/20141120/pcautoapp/index.html'

       };

       //三元运算

       // window.location.href = isAndroid? urls.android : isiOS? urls.ios : urls.other;

       //简化

       if(isAndroid){

              window.location.href=urls.android;

       }else if(isiOS){

              window.location.href=urls.ios;

       }else{

              window.location.href=urls.other;

       }

}

downApp();

 

<a href="javascript:void(0)" onclick="downApp()">点击下载应用</a>

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h23648.shtml

如对文章有任何疑问请提交到DIV CSS论坛,或有任何网页制作CSS问题立即到CSS论坛发贴求解 或 直接DIVCSS5网页顶部搜索遇到DIVCSS疑问。
CSS教程文章修订日期:2018-08-14 17:37 原创:DIVCSS5
本文www.divcss5.com DIVCSS5版权所有。