您的位置:首页 > Web前端 > JavaScript

js判断手机还是pc并跳转相关页面

2016-05-11 18:36 751 查看
<script type="text/javascript">
function GetRequest() {
var url = location.search; //��ȡurl��"?"������ִ�
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}

var request = new Object();
request = GetRequest();

checkWidth();

function checkWidth() {

//if (undefined != request["Account"] && undefined != request["paihangbang"] && undefined != request["benlunmingci"] && undefined != request["tunshirenshu"] && undefined != request["benlunzuidatizhong"]) {
//	window.location.href = "share.html"+location.search;
//	return;
//}

var math = Math.floor(Math.random()*10);

if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if(window.location.href.indexOf("?mobile")<0){
try{
if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
}else if(/iPad/i.test(navigator.userAgent)){
}else{
}

if(undefined != request["Account"] && undefined != request["id"])
{
window.location.href = "index_mobile_share.html"+location.search;
return;
}else{

if(math <= 5){
window.location.href="index_mobile.html"+location.search;
return;
}else{
window.location.href="index_mobileA.html"+location.search;
return;
}

}
}catch(e){}
}
}else{
if(math <= 5){
window.location.href="index_PC.html"+location.search;
}else{
window.location.href="index_PCA.html"+location.search;
}

}
}

</script>


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: