I am trying to use the media attribute to only link my javascript files on to mobile devices, not on desktop ones.
Here's my link tag:
<script type="text/javascript" media="screen and (max-width : 850px)" src="mobile.js"></script>
But this isn't working, it links to JS to everything.
How do I only link a JS file if it meets those query conditions?
If I can't how do I only run JS if it is on mobile?
How about using javascript for that?
<script type="text/javascript">
if (screen.width < 980) {
document.write('<script type="text/javascript" src="mobile.js"></script>');
}
</script>
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