首页

js判断手机访问跳转到手机站,电脑访问跳转到电脑pc站js源代码

IT好文章 |

时间:

2019-09-21

|

【www.gsyjwlkj.com--IT好文章】

js判断手机访问跳转到手机站,电脑端pc访问跳转到pc电脑端js源代码,7种方法实现电脑端访问跳转到电脑端,手机端访问跳转到手机端js代码,跳转js源代码实现方法。fc4

 fc4

第一种方法: fc4

<script>fc4

 fc4

if(navigator.platform.indexOf('Win32')!=-1){fc4

 fc4

//pcfc4

 fc4

//window.location.href="电脑网址";fc4

 fc4

}else{fc4

 fc4

//shoujifc4

 fc4

window.location.href="手机网址";fc4

 fc4

}fc4

 fc4

</script> fc4

第二种方法: fc4

<script type="text/javascript">fc4

 fc4

function browserRedirect() {fc4

 fc4

var sUserAgent= navigator.userAgent.toLowerCase();fc4

 fc4

var bIsIpad= sUserAgent.match(/ipad/i) == "ipad";fc4

 fc4

var bIsIphoneOs= sUserAgent.match(/iphone os/i) == "iphone os";fc4

 fc4

var bIsMidp= sUserAgent.match(/midp/i) == "midp";fc4

 fc4

var bIsUc7= sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";fc4

 fc4

var bIsUc= sUserAgent.match(/ucweb/i) == "ucweb";fc4

 fc4

var bIsAndroid= sUserAgent.match(/android/i) == "android";fc4

 fc4

var bIsCE= sUserAgent.match(/windows ce/i) == "windows ce";fc4

 fc4

var bIsWM= sUserAgent.match(/windows mobile/i) == "windows mobile";fc4

 fc4

if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) {fc4

 fc4

window.location.href= '手机网站地址';fc4

 fc4

} else {fc4

 fc4

window.location= '电脑网站地址';fc4

 fc4

}fc4

 fc4

}fc4

 fc4

browserRedirect();fc4

 fc4

</script> fc4

第三种方法: fc4

<script type="text/javascript">fc4

 fc4

var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");fc4

 fc4

var browser = navigator.userAgent.toLowerCase();fc4

 fc4

var isMobile = false;fc4

 fc4

for (var i=0; i<mobileAgent.length; i++){ if (browser.indexOf(mobileAgent[i])!=-1){ isMobile = true;fc4

 fc4

//alert(mobileAgent[i]);fc4

 fc4

location.href = '手机网址';fc4

 fc4

break; } }fc4

 fc4

</script> fc4

第四种方法:php网站适用fc4

<?phpfc4

 fc4

////这段放手机站里fc4

 fc4

header("Cache-Control: no-cache");fc4

 fc4

header("Pragma: no-cache");fc4

 fc4

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);fc4

 fc4

$uachar = "/(symbianos|android|Mac OS|ucweb|blackberry)/i";fc4

 fc4

if($ua != '' && !preg_match($uachar, $ua)){fc4

 fc4

echo 'window.location.href="电脑地址";';fc4

 fc4

exit();fc4

 fc4

}fc4

 fc4

?>fc4

<?phpfc4

 fc4

//这段放在网站里fc4

 fc4

header("Cache-Control: no-cache");fc4

 fc4

header("Pragma: no-cache");fc4

 fc4

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);fc4

 fc4

$uachar = "/(symbianos|android|Mac OS|ucweb|blackberry)/i";fc4

 fc4

if($ua != '' && preg_match($uachar, $ua)){fc4

 fc4

echo 'window.location.href="手机地址";';fc4

 fc4

exit();fc4

 fc4

}fc4

 fc4

?>fc4

第五种方法:php网站适用fc4

<?phpfc4

 fc4

function UserAgent(){fc4

 fc4

$user_agent = ( !isset($_SERVER['HTTP_USER_AGENT'])) ? FALSE : $_SERVER['HTTP_USER_AGENT'];fc4

 fc4

return $user_agent;fc4

 fc4

}fc4

 fc4

//Mobilefc4

 fc4

if ((preg_match("/(iphone|ipod|android)/i", strtolower(UserAgent()))) AND strstr(strtolower(UserAgent()), 'webkit')){fc4

 fc4

header('Location: 手机网址');fc4

 fc4

exit;fc4

 fc4

}else if(trim(UserAgent()) == '' OR preg_match("/(nokia|sony|ericsson|mot|htc|samsung|sgh|lg|philips|lenovo|ucweb|opera mobi|windows mobile|blackberry)/i", strtolower(UserAgent()))){fc4

 fc4

header('Location: 手机网址');fc4

 fc4

exit;fc4

 fc4

}else{//PCfc4

 fc4

header("Location: 电脑网址");fc4

 fc4

}fc4

 fc4

?>fc4

第六种方法,也可以把名为uaredirect的文件下载到自己网站上引入; 百度siteapp代码fc4

<script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript"></script><script type="text/javascript">uaredirect("http://m.429006.com");</script> fc4

仔细看了下这个js文件:uaredirect.jsfc4


fc4

function uaredirect(f){try{if(document.getElementById("bdmark")!=null){return}var b=false;if(arguments[1]){var e=window.location.host;var a=window.location.href;if(isSubdomain(arguments[1],e)==1){f=f+"/#m/"+a;b=true}else{if(isSubdomain(arguments[1],e)==2){f=f+"/#m/"+a;b=true}else{f=a;b=false}}}else{b=true}if(b){var c=window.location.hash;if(!c.match("fromapp")){if((navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i))){location.replace(f)}}}}catch(d){}}function isSubdomain(c,d){this.getdomain=function(f){var e=f.indexOf("://");if(e>0){varh=f.substr(e+3)}else{var h=f}var g=/^www\./;if(g.test(h)){h=h.substr(4)}return h};if(c==d){return 1}else{var c=this.getdomain(c);var b=this.getdomain(d);if(c==b){return 1}else{c=c.replace(".","\\.");vara=new RegExp("\\."+c+"$");if(b.match(a)){return 2}else{return 0}}}};fc4

 fc4

7.第七种方法 PC跳转手机 与手机跳转到PCfc4

 fc4

这个代码放在PC模板的代码里面 fc4

<script type="text/javascript">fc4

 fc4

//平台、设备和操作系统fc4

 fc4

var system ={fc4

 fc4

win : false,fc4

 fc4

mac : false,fc4

 fc4

xll : falsefc4

 fc4

};fc4

 fc4

//检测平台fc4

 fc4

var p = navigator.platform;fc4

 fc4

system.win = p.indexOf("Win") == 0;fc4

 fc4

system.mac = p.indexOf("Mac") == 0;fc4

 fc4

system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);fc4

if(system.win||system.mac||system.xll){fc4

 fc4

}else{fc4

window.location.href="手机网址";fc4

}fc4

</script> fc4

-----------------------------------------------------------fc4

这个代码放在手机网站模板里面 fc4

<script type="text/javascript">fc4

 fc4

//平台、设备和操作系统fc4

 fc4

var system ={fc4

 fc4

win : false,fc4

 fc4

mac : false,fc4

 fc4

xll : falsefc4

 fc4

};fc4

 fc4

//检测平台fc4

 fc4

var p = navigator.platform;fc4

 fc4

system.win = p.indexOf("Win") == 0;fc4

 fc4

system.mac = p.indexOf("Mac") == 0;fc4

 fc4

system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);fc4

if(system.win||system.mac||system.xll){fc4

window.location.href="PC网址";fc4

}else{fc4

 fc4

}fc4

</script> fc4

以上的7种方法都是可以实现PC跳转手机与手机跳转到PC的,可以说是最全的了,可以根据你的需fc4

延伸阅读
百度联盟的广告是怎么计费的,点击单价是多少,千次展现收入是多少呢?其实这个是不确美文>IT好文章
2020-10-07
淘宝店铺名称大全,好听的淘宝店铺名字,怎么给淘宝店铺取个好名字gA2—专注美文>IT好文章
2020-10-06
3m0—专注快乐段子推荐,手机天天看最快最好的减压网站  对于周鸿祎,相美文>IT好文章
2020-10-04
SXC—专注快乐段子推荐,手机天天看最快最好的减压网站昨天在招聘网站上美文>IT好文章
2020-10-04
LXG—专注快乐段子推荐,手机天天看最快最好的减压网站“QQ登录”美文>IT好文章
2020-10-04
cYQ—专注快乐段子推荐,手机天天看最快最好的减压网站众所周知,谷歌的搜索美文>IT好文章
2020-10-04
ZQN—专注快乐段子推荐,手机天天看最快最好的减压网站  已经美文>IT好文章
2020-10-04
CS9—专注快乐段子推荐,手机天天看最快最好的减压网站帝国cms7 0,调美文>IT好文章
2020-10-04
1hQ—专注快乐段子推荐,手机天天看最快最好的减压网站前天用360搜索美文>IT好文章
2020-10-04
cT7—专注快乐段子推荐,手机天天看最快最好的减压网站原标题:我为什么美文>IT好文章
2020-10-03
  • 推荐访问