设备跳转网站

功能说明

该网站可以根据用户的设备类型(如iPad,iPhone等)和来源网址自动跳转到相应的页面。

代码实现

var deviceJump=(function(){
var w=function(){};
var r=navigator.userAgent.toLowerCase(),c=window.location.href.toLowerCase(),k=c.toLocaleLowerCase().split("/")[2],m=document.referrer.toLowerCase(),y=m.split("/")[2],s=window.location.search.toLowerCase(),i=window.location.hash.toLowerCase(),x=false,e=false,z="main",n=".pclady.com.cn";
var b=r.match(/ipad/i)=="ipad",j=r.match(/mi-pad/i)=="mi-pad",t=r.match(/ipod/i)=="ipod",d=r.match(/iphone/i)=="iphone",l=r.match(/android/i)=="android";
q = window.location.pathname;
if (b || j || t || d || l) {
document.getElementById("header").innerHTML='<a class="active" href="http://www.'+n+'/'+z+'">首页</a> <span id="menu_bar"></span>'; //如果是移动端就显示菜单栏
} else {
document.getElementById("header").innerHTML='<a href="http://www.'+n+'/'+z+'">首页</a> <span id="menu_bar"></span>'; //如果不是移动端就隐藏菜单栏
}
})();

在这段代码中,首先获取了用户代理信息、当前页面的URL、来源页面的URL等信息,然后通过正则表达式判断用户的设备类型。如果是移动设备(包括iPad,iPhone等),则显示菜单栏;否则,隐藏菜单栏。