判断pc端或移动端并跳转

判断pc端或移动端并跳转

代码目录:

index.html代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function IsPC() {
        var userAgentInfo = navigator.userAgent;
        var Agents = ["Android", "iPhone",
            "SymbianOS", "Windows Phone",
            "iPad", "iPod"];
        var flag = true;
        for (var v = 0; v < Agents.length; v++) {
            if (userAgentInfo.indexOf(Agents[v]) > 0) {
                flag = false;
                break;
            }
        }
        return flag;
    }

    var flag = IsPC();
    if(flag){
        window.location.href="./studentp/index.html#/";
    }else {
        window.location.href="./studenti/index.html#/";
    }</script>
</body>
</html>

 

参考自:http://www.jb51.net/article/48939.htm

posted @ 2017-12-24 21:01  莫小龙  阅读(447)  评论(0编辑  收藏  举报