当前位置:主页 >> JavaScript >> 正文
js代码实现移动设备与电脑之间的跳转
阅读:748 输入:2015-12-24 10:17:42

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

<script type="text/javascript"> 
//平台、设备和操作系统 
var system ={ 
win : false, 
mac : false, 
xll : false
}; 
//检测平台 
var p = navigator.platform; 
system.win = p.indexOf("Win") == 0; 
system.mac = p.indexOf("Mac") == 0; 
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
if(system.win||system.mac||system.xll){   
}else{
window.location.href="手机网址";
}
</script>

此代码放在手机网站模板里面:

<script type="text/javascript"> 
//平台、设备和操作系统 
var system ={ 
win : false, 
mac : false, 
xll : false
};
//检测平台
var p = navigator.platform; 
system.win = p.indexOf("Win") == 0; 
system.mac = p.indexOf("Mac") == 0; 
system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
if(system.win||system.mac||system.xll){   
window.location.href="PC网址";
}else{ 
}
</script>

js判断移动端和电脑端跳转代码:

var browser_class = navigator.userAgent;
var browser_class_name1 = browser_class.match("Mobile");
var browser_class_name2 = browser_class.match("mobile");
var location_url = window.location.href;
if (browser_class_name1 != null || browser_class_name2 != null){
if (location_url.match("wap") == null){
window.location.href="http://wap.xxxx.com";
}
}else{
if (location_url.match("3g") != null || location_url.match("wap") != null){
window.location.href="http://wap.xxxx.com";
}
}