Heim  >  Artikel  >  Web-Frontend  >  基于JavaScript代码实现pc与手机之间的跳转_javascript技巧

基于JavaScript代码实现pc与手机之间的跳转_javascript技巧

WBOY
WBOYOriginal
2016-05-16 15:24:08878Durchsuche

这个代码放在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>

PS:JS判断手机端和PC端跳转代码

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";
    }
 }

以上内容是小编给大家介绍的基于JavaScript代码实现pc与手机之间的跳转的全部叙述,希望大家喜欢。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn