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>

  

时间: 2024-08-26 07:28:53

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

js判断手机浏览器操作系统和微信浏览器的方法

做手机端的前端开发,少不了对手机平台的判断.如,对于app下载,就要判断在Android平台下就显示Android下载提示:在iOS平台下就显示iOS下载提示. 今天就为大家介绍一下用js判断手机客户端平台及系统平台的方法: <script type="text/javascript"> //手机端判断各个平台浏览器及操作系统平台 function checkPlatform(){ if(/android/i.test(navigator.userAgent)){ docu

js判断手机浏览器

最新浏览器识别合并. demo:http://v.qq.com    ->   http://v.qq.com/h5 http://v.qq.com/    ->   http://v.qq.com/h5 http://v.qq.com/h5    ->   http://v.qq.com/h5 <script type="text/javascript"> (function(W){ if(!/\/h5/.test(W.location.pathname

百度Site App的uaredirect.js实现手机访问,自动跳转网站手机版

以下为代码,可放置在网站foot底部文件,或者haead顶部文件,建议将代码放在网站顶部,这样可以实现手机访问立即跳转! <script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script><script type="text/javascript">uaredirec

php js 判断手机访问

<?php function isMobile(){ $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $useragent_commentsblock=preg_match('|\(.*?\)|',$useragent,$matches)>0?$matches[0]:''; function CheckSubstrs($substrs,$text){ foreach($subst

js判断手机是否安装了某一款app,有则打开,没有去下载

function openApp(){ if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { var loadDateTime = new Date(); window.setTimeout(function() { var timeOutDateTime = new Date(); if(timeOutDateTime - loadDateTime < 5000) { window.location = "要跳转的下载app页面

原生JS判断手机系统

点击图片,判断手机操作系统,根据手机系统跳转不同链接. function imgHref(){ var userAgent = navigator.userAgent; var isAndroid = userAgent.indexOf('Android') > -1 || userAgent.indexOf('Adr') > -1; //android终端 var isiOS = !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //io

js判断手机浏览器是横屏or竖屏

移动端的浏览器一般都支持window.orientation这个参数,通过这个参数可以判断出手机是处在横屏还是竖屏状态. 从而根据实际需求而执行相应的程序.通过添加监听事件onorientationchange,进行执行就可以了. //判断手机横竖屏状态: function hengshuping(){ if(window.orientation==180||window.orientation==0){ alert("竖屏状态!") } if(window.orientation==

JS判断手机访问页面,根据手机访问或者PC访问跳转

当用户访问你网站时,如果是PC端访问,则不作处理,如果是手机或者平板访问,就跳转到自己定义的手机页面去,这个在做webapp的时候经常用到,把代码分享给大家,希望对大家有所帮助. 首先,你要在页面中引用一个jsuaredirect.js,js源码如下: function uaredirect(f){try{if(document.getElementById("bdmark")!=null){return}var b=false;if(arguments[1]){var e=windo

利用JS实现手机访问PC网址自动跳转到wap网站

方法一:使用百度siteapp中的js进行判断 <script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script><script type="text/javascript">uaredirect("需要跳转的手机网址")</script&g