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'; }