I want to be able disable certain scripts that are in the head section of my page when a mobile device is detected.
At the minute I have this:
$(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.
Use following
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
// some code..
}else
{
//Now include js files
}
for your second Question
use
if (window.width > 479) {
$('head').append('<link rel="stylesheet" href="style2.css" type="text/css" />');
}
here you can include css or js file.
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
// what you want to run in mobile
}
you can do something like this to test if it is a mobile.
if you are only concerned with the width :
if ($(window).width() <= 479) {
do stuff
}
or you can use this package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With