I have a series of jQuery scripts on my site that I want to only run if the users screen width is greater than 960px. I know that you can't detect screen size using php but is there a way to create something to this effect:
<? php
if [METHOD TO DETECT SCREEN SIZE] > 960px {
echo '<script src="js/nbw-parallax.js" type="text/javascript"></script>';
}
?>
PHP is server side and can't grab your screen width and height.
You have to use javascript.
if( $(window).width() > 960 ) {
$.getScript('js/nbw-parallax.js');
}
if( window.innerWidth > 960 ) {
//Your Code
}
Why not use jQuery?
if( $(window).width() > 960 )
{
$.ajax({
url: 'js/nbw-parallax.js',
dataType: "script",
success: function() {
//success
}
});
}
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