C
C
Captain Cocoa2015-10-16 12:42:39
css
Captain Cocoa, 2015-10-16 12:42:39

How to disable scripts connected to the page through @media screen?

Hello everyone, here's the bottom line, there is an adaptive site.
The script is connected in the body

<script type='text/javascript' src='script.js'></script>

When the full version of the site is desktop, then the script is needed, when the mobile @media screen and (max-width: 480px) {}script is not needed, as it interferes.
How to remove it from the page (or comment it out there or something else) when the mobile version is displayed?
Or is it not possible to do this through the media screen at all? Is there any alternative then?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-10-16
@RadCor

The simplest is to wrap the internals of your script in if ($( document ).width() > 480).
But it is more correct, of course, to load it only when it is really needed:

if ($( document ).width() > 480) {
  $.getScript( "script.js");
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question