27
2017
09

自动判断访问设备

当前是PC端

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <script> var userAgentInfo = navigator.userAgent; var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"); var flag = false; var v=0 for ( v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = true; break; } } if(flag){ window.location='m.html'; //如果是移动设备访问,就跳转到魔客吧。请更改为你的网址。 } </script>
</head>
<body>

    <h1>当前是PC端</h1>

</body>
</html>

这里是移动端

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    <script> var userAgentInfo = navigator.userAgent; var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"); var flag = false; var v=0 for ( v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = true; break; } } if(!flag){ window.location='index.html'; //如果是PC设备访问,就跳转到指定的网址。 } </script>
    </head>
    <body>
        <h1>这里是移动端</h1>
    </body>
</html>
上一篇:表单验证 下一篇:Android MagicaSakura多主题框架