JS判断访问设备进行页面跳转

<script type="text/javascript">
        function redirect(){
            location.href = href;
        }

        var url_parts = document.URL.split('?');
        var query = url_parts.length == 2 ? ('?' + url_parts[1]) : '';
        var href = '/';
        var ua = navigator.userAgent.toLowerCase();
        console.log("url:"+document.URL);
        console.log("url_parts:"+url_parts);
        console.log("query:"+query);
        console.log("ua:"+ua);
        /* 
            "http://127.0.0.1:8080/courseCentre/couserInfo.jspx?courseId=1" 
                url_parts:http://127.0.0.1:8080/courseCentre/couserInfo.jspx,courseId=1  
                query:?courseId=1  
                ua:mozilla/5.0 (windows nt 10.0; wow64; rv:55.0) gecko/20100101 firefox/55.0
                微信端地址:http://127.0.0.1:8080/course_wechat.jspx?courseId=5
        */
    if (/iphone|ipad|ipod/.test(ua)) {
        href = 'http://localhost:8080/course_wechat.jspx'+query;
        //__ga('set', 'page', '/download/ios' + query);
        //__ga('send', 'pageview');
        //__ga('send', 'event', 'app', 'download-via-qrcode', 'ios', {'hitCallback': redirect});
        setTimeout(redirect, 2000);
    } else if (/android/.test(ua)) {
        href = 'http://localhost:8080/course_wechat.jspx'+query;
        //__ga('set', 'page', '/download/android' + query);
        //__ga('send', 'pageview');
        //__ga('send', 'event', 'app', 'download-via-qrcode', 'android-local', {'hitCallback': redirect});
        setTimeout(redirect, 2000);
    } else if (/windows phone|blackberry/.test(ua)) {
        //__ga('set', 'page', '/download/other' + query);
        //__ga('send', 'pageview');
        alert('抱歉,暂不支持您的系统');
        location.href = '/';
    } else {
        //__ga('send', 'pageview');
        //location.href = 'www.baidu.com'; 此处访问http://127.0.0.1:8080/courseCentre/www.baidu.com
        //location.href='http://192.168.4.108:8080/course_wechat.jspx?courseId=5/';
        //location.href='/courseCentre/couserInfo.jspx?courseId=1';
    }

 

转载于:https://www.cnblogs.com/againn/p/7602235.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值