本文主要是介绍js实现打开网页设备判断,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8" />
<title>js实现打开网页设备判断</title>
<script>
/*判断打开设备*/
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);
var local= location.href;
//跳转语句
if(system.win||system.mac||system.xll){//此处说明打开该网页设备为pc端alert("该设备为PC端");//若用移动端网址路径访问则自动跳转到对应pc端路径if(local=='http://www.centlight.com/mobile_web.html'){window.location.href="http://www.centlight.com/child_web.html";}else if(local=='http://www.centlight.com/mobile_ui.html'){window.location.href="http://www.centlight.com/child_ui.html";}else if(local=='http://www.centlight.com/mobile_php.html'){window.location.href="http://www.centlight.com/child_php.html";}else{window.location.href="http://www.centlight.com/";}
}else{//此处说明打开该网页设备为移动端alert("该设备为移动端");//若用PC端网址路径访问则自动跳转到对应移动端路径if(local=='http://www.centlight.com/child_web.html'){window.location.href="http://www.centlight.com/mobile_web.html";}else if(local=='http://www.centlight.com/child_ui.html'){window.location.href="http://www.centlight.com/mobile_ui.html";}else if(local=='http://www.centlight.com/child_php.html'){window.location.href="http://www.centlight.com/mobile_php.html";}else{window.location.href="http://www.centlight.com/mobile.html";}
}</script>
</head>
<body>
</body>
</html>
这篇关于js实现打开网页设备判断的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!