Javascript屏幕分辨率检测和重定向 函数检测(){ var uagent=navigator.userAgent.toLowerCase(); var mobile=false; 变量搜索\u字符串=[ “iphone”, “ipod”, “ipad”, “系列60”, “塞班”, “安卓”, “windows ce”, “windows7phone”, “w7p”, “黑莓”, “棕榈树” ]; for(搜索字符串中的i){ if(uagent.search(search_strings[i])>-1) 移动=真; } 返回手机; } if(detect()) window.location=“mydomain/mobile”; 如果(屏幕宽度1900){ window.location.replace('mydomain/1900'); }

Javascript屏幕分辨率检测和重定向 函数检测(){ var uagent=navigator.userAgent.toLowerCase(); var mobile=false; 变量搜索\u字符串=[ “iphone”, “ipod”, “ipad”, “系列60”, “塞班”, “安卓”, “windows ce”, “windows7phone”, “w7p”, “黑莓”, “棕榈树” ]; for(搜索字符串中的i){ if(uagent.search(search_strings[i])>-1) 移动=真; } 返回手机; } if(detect()) window.location=“mydomain/mobile”; 如果(屏幕宽度1900){ window.location.replace('mydomain/1900'); },javascript,redirect,screen,resolution,detection,Javascript,Redirect,Screen,Resolution,Detection,你好,我有这个代码工作良好。我想知道,如果可能的话,添加更多的两个屏幕分辨率(1300和1200) 如果通过“移动”访问=mydomain/mobile 如果通过桌面访问“resolution 1900 plus”=mydomain/1900 如果通过桌面访问“分辨率1600至1899”=mydomain/1600 如果通过桌面访问“分辨率1300至1599”=mydomain/1300 如果通过桌面访问“分辨率1024至1299”=mydomain/1200 谢谢 首先,更好的方法是 如果您想

你好,我有这个代码工作良好。我想知道,如果可能的话,添加更多的两个屏幕分辨率(1300和1200)

如果通过“移动”访问=mydomain/mobile

如果通过桌面访问“resolution 1900 plus”=mydomain/1900

如果通过桌面访问“分辨率1600至1899”=mydomain/1600

如果通过桌面访问“分辨率1300至1599”=mydomain/1300

如果通过桌面访问“分辨率1024至1299”=mydomain/1200


谢谢

首先,更好的方法是

如果您想使用
javascript
只需添加
If-else
语句

<script>
    function detect() {
        var uagent = navigator.userAgent.toLowerCase();
        var mobile = false;
        var search_strings = [
            "iphone",
            "ipod",
            "ipad",
            "series60",
            "symbian",
            "android",
            "windows ce",
            "windows7phone",
            "w7p",
            "blackberry",
            "palm"
        ];

        for (i in search_strings) {
            if (uagent.search(search_strings[i]) > -1)
                mobile = true;
        }

        return mobile;
    }

    if (detect()) 
        window.location = "mydomain/mobile";
</script>

<script type="text/javascript">
    if (screen.width <= 1600) {
        window.location.replace('mydomain/1600');
    }
    if (screen.width > 1900) {
        window.location.replace('mydomain/1900');
    }
</script>
if (screen.width >= 1900) {
    window.location.replace('mydomain/1900');
} else if (screen.width >= 1600 && screen.width < 1900) {
    window.location.replace('mydomain/1600');
} else if (screen.width >= 1300 && screen.width < 1600) {
    window.location.replace('mydomain/1300');
} else if (screen.width >= 1024 && screen.width < 1200) {
    window.location.replace('mydomain/1024');
} else {
    alert("error");
}
var uagent = navigator.userAgent.toLowerCase();
var mobile = false;
var search_strings = [
"iphone",
"ipod",
"ipad",
"series60",
"symbian",
"android",
"windows ce",
"windows7phone",
"w7p",
"blackberry",
"palm"
];

function detect() {
    for (i in search_strings) {
        if (uagent.search(search_strings[i]) > -1){  
            mobile = true;
            return mobile;
        }
    }
    return mobile;
}