如果移动设备禁用某些脚本 [英] If mobile disable certain scripts
本文介绍了如果移动设备禁用某些脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够在检测到移动设备时禁用页面顶部的某些脚本.
I want to be able disable certain scripts that are in the head section of my page when a mobile device is detected.
目前我有这个:
$(function(){
var mobile;
if (window.width <= 479) {
//don't load these scripts
}
else {
//load all scripts
}
});
我正在努力寻找代码以在检测到移动宽度时禁用脚本.任何帮助或其他想法将不胜感激.
I'm struggling to find the code to disable the scripts from running when mobile width is detected. Any help or other ideas would be much appreciated.
推荐答案
使用以下内容
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
// some code..
}else
{
//Now include js files
}
第二个问题
使用
if (window.width > 479) {
$('head').append('<link rel="stylesheet" href="style2.css" type="text/css" />');
}
您可以在其中包含CSS或JS文件.
here you can include css or js file.
这篇关于如果移动设备禁用某些脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文