码迷,mamicode.com
首页 > 移动开发 > 详细

原生JS判断手机系统

时间:2019-09-27 10:29:46      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:func   click   根据   use   agent   navig   img   ntb   nes   

点击图片,判断手机操作系统,根据手机系统跳转不同链接。

function imgHref(){
    var userAgent = navigator.userAgent;
    var isAndroid = userAgent.indexOf('Android') > -1 || userAgent.indexOf('Adr') > -1; //android终端
    var isiOS = !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    if(isAndroid){
        // 安卓
        window.location.href ="http://shouji.baidu.com/software/...";
    }else if(isiOS){
        // ios
        window.location.href="https://itunes.apple.com/cn/app/...";
    }
};
var img_href = document.getElementById('href');
img_href.onclick = imgHref;

原生JS判断手机系统

标签:func   click   根据   use   agent   navig   img   ntb   nes   

原文地址:https://www.cnblogs.com/jessie-xian/p/11596087.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!