如果移动禁用某些脚本

我希望能够在检测到移动设备时禁用位于我页面的head部分的某些脚本。

在那一刻我有这个:

$(function(){ var mobile; if (window.width <= 479) { //don't load these scripts } else { //load all scripts } }); 

当我检测到移动宽度时,我很难找到禁止脚本运行的代码。 任何帮助或其他想法将不胜感激。

使用以下

 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(''); } 

在这里你可以包括css或js文件。

 if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) { // what you want to run in mobile } 

你可以做这样的事情来测试它是否是移动设备。

如果你只关心宽度:

 if ($(window).width() <= 479) { do stuff }