原生JS判断手机系统

作者: 贤总_ | 来源:发表于2019-06-12 16:39 被阅读3次

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

    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判断手机系统

        本文链接:https://www.haomeiwen.com/subject/bynlfctx.html