Given: "if mobile then do not load JS", and presuming "mobile" is defined by screens with a width of 480 pixels or less, then something like the following should work:
<script>
if (screen && screen.width > 480) {
document.write('<script type="text/javascript" src="foo.js"></script>');
}
</script>
That will add the script element only if the screen is greater than 480 pixels wide.
The CSS rule in the OP is:
<... media="only screen and (max-device-width: 480px)" ...>
which will target screens of 480 pixels or less, which is contrary to to the first statement. Therefore change >
to <=
if the script should run on small screens and not run on larger ones.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…