Home > Backend Development > PHP Tutorial > javascript - Is there any js statement to prevent specific js and css from loading on the mobile terminal?

javascript - Is there any js statement to prevent specific js and css from loading on the mobile terminal?

WBOY
Release: 2016-08-27 09:06:50
Original
1058 people have browsed it

My website uses static cache, which causes the wp_is_mobile()function to fail
Is there any js method that can replace the wp_is_mobile() function? In order to
make certain js and css load only on the PC side, but not on the mobile side. (Baidu and Google are broken, if you have a good method, please help)

Reply content:

My website uses

static cache, which causes the wp_is_mobile()function to failIs there any js method that can replace the wp_is_mobile() function
? In order to make certain js and css load only on the PC side, but not on the mobile side.
(Baidu and Google are broken, if you have a good method, please help)

Looking at the problem description, it is necessary to write a wp_is_mobile method. If so, provide a simple method.

<code>var browserRedirect = function() {
    var sUserAgent = navigator.userAgent.toLowerCase();
    var systemclass = {};
    systemclass.bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    systemclass.bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    systemclass.bIsMidp = sUserAgent.match(/midp/i) == "midp";
    systemclass.bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    systemclass.bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    systemclass.bIsAndroid = sUserAgent.match(/android/i) == "android";
    systemclass.bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    systemclass.bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
    systemclass.bIsWX = sUserAgent.match(/MicroMessenger/i) == "micromessenger";
    return systemclass;
};
var nowclass = browserRedirect();

if (nowclass.bIsIpad || nowclass.bIsIphoneOs || nowclass.bIsMidp || nowclass.bIsUc7 || nowclass.bIsUc || nowclass.bIsAndroid || nowclass.bIsCE || nowclass.bIsWM) {
    if (nowclass.bIsIphoneOs || nowclass.bIsIpad || nowclass.bIsMidp) { //如果是ios移动设备
        window.location.href = "ios需要跳转的地方";
        if (nowclass.bIsWX) { //解决以微信内核浏览器打开无法直接跳转给出提示点击跳转至safari打开
            document.getElementById("tipsid").style.display = "block";
        }
    } else if (nowclass.bIsAndroid) { //如果是android移动设备
        window.location.href = "android需要跳转的地方";
    }
} else {
    window.location.href = "PC端跳转去的地方";
}

</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template