• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

javascript – 有没有js语句 使特定的js和css在移动端不加载?

php 搞代码 4年前 (2022-01-23) 21次浏览 已收录 0个评论
文章目录[隐藏]

我的网站由于用了静态缓存,而导致了wp_is_mobile()这个函数失效了
请问有没有js的方法可以替代掉wp_is_mobile()这个函数呢?
为了使某些js和css在仅在在PC端加载,而移动端不加载。
(百度,Google已烂,如果你有好的方法,恳请帮助 )

@本文来*源gaodai#ma#com搞*!代#%^码$网*

回复内容:

我的网站由于用了静态缓存,而导致了wp_is_mobile()这个函数失效了
请问有没有js的方法可以替代掉wp_is_mobile()这个函数呢?
为了使某些js和css在仅在在PC端加载,而移动端不加载。
(百度,Google已烂,如果你有好的方法,恳请帮助 )

看问题描述是需要写一个wp_is_mobile方法,如果是这样的话,提供个简单方法。

<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>

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:javascript – 有没有js语句 使特定的js和css在移动端不加载?
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址