pc端网页与手机端之间跳转

博主:adminadmin 2022-02-24 881 0条评论
温馨提示:文章已超过807天没有更新,若内容或图片失效,请留言反馈!
摘要: <script>    // PC端 移动端 跳转   &n...
<script>
    // PC端 移动端 跳转
    var is_mobi = navigator.userAgent.toLowerCase().match(/(ipod|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null;
        if (!is_mobi) {
            window.location.href="index.html" 
        }
</script>
这个放手机上
这个放pc上跳手机
<script>
        function isPcFun() {
            let u = navigator.userAgent;
            let Agents = [
                "Android",
                "iPhone",
                "webOS",
                "BlackBerry",
                "SymbianOS",
                "Windows Phone",
                "iPad",
                "iPod"
            ];
            let flag = true;
            for (let i = 0; i < Agents.length; i++) {
                if (u.indexOf(Agents[i]) > 0) {
                    flag = false;
                    break;
                }
            }
            return flag;
        }
        var isPc = isPcFun();
        if (!isPc) {
            window.location.href = "m.html";
        }
    </script>


文章最后编辑时间:2022-04-25 10:28:29
分享