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

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

  

posted @ 2016-05-11 18:36  唸随爱  阅读(751)  评论(0编辑  收藏  举报