js判读是否为手机端跳转

于 2025-01-17 发布 阅读量524  

function isMobile() {
    var userAgentInfo = navigator.userAgent;
    var mobileAgents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
    for (var i = 0; i < mobileAgents.length; i++) {
        if (userAgentInfo.indexOf(mobileAgents[i]) > -1) {
            return true;
        }
    }
    return false;
}

if (isMobile()) {
    window.location.href = ""; // 跳转到移动端域名
} else {
    window.location.href = ""; // 跳转到PC端域名
}