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

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

时间:2016-05-11 19:35:57      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

<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>

  

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

标签:

原文地址:http://www.cnblogs.com/xupeiyu/p/5483167.html

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