隐藏移动设备的Javascript文件 [英] Hide Javascript file for mobile devices

查看:63
本文介绍了隐藏移动设备的Javascript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在设备(移动设备)上,是否有任何方法可以阻止javascript文件的加载?我已经做出了响应式设计,并且有一些脚本没有用于移动版本,因此如果不需要加载它们会很好.

is there anyway to stop a javascript file from being loaded when on a device (mobile)? I've made a responsive design and there are a few scripts that do not get used for the mobile version so it would be good if they do not have to load.

非常感谢

推荐答案

检查浏览器是否不是ismobiledocument.write不在脚本中:

Check if the browser is not ismobile and document.write out the script:

<script type="text/javascript">
    var ismobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));

    if(!ismobile) document.write('<script src="http://source.com/script.js"></script>');

</script>

这篇关于隐藏移动设备的Javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆