Note that there are some explanatory texts on larger screens.

plurals
  1. PODisabling specific javascript loaded with the <script> tag
    primarykey
    data
    text
    <p>I have this JavaScript file loaded with the <code>&lt;script&gt;</code> HTML tag:</p> <pre><code>&lt;script type="text/javascript" charset="utf-8" src="adobeEdge_animation.js"&gt;&lt;/script&gt; </code></pre> <p>I want to make it work only when the <code>width</code> of the browser is over <code>500px</code>.</p> <p>I know a way to do it, which is copying basically everything of the file and paste it inside of the <code>resize</code> event, like this:</p> <pre><code>$(document).ready(function(){ if ($(window).width() &gt; 480) { //all the code inside of that file } }); $(window).resize(function(){ if ($(this).width() &gt; 480) { //all the code inside of that file } } </code></pre> <p>But I'm still sure there's another way, I'm looking for a simpler or easier way to do it.</p> <h2>EDIT:</h2> <p>The structure of the <code>index.php</code> file makes it's content dynamic, </p> <pre><code>&lt;body&gt; &lt;div id="big_wrapper"&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script&gt;jQuery.get(source);&lt;/script&gt; &lt;?php include('includes/header.php'); ?&gt; &lt;article&gt; &lt;section&gt; &lt;?php if(isset($p)){ switch ($p) { case 'introduccion': include('content/introduccion.php'); break; case 'marketing_digital': include('content/marketing.php'); break; case 'diseño_web': include('content/web.php'); break; case 'diseño_grafico': include('content/grafico.php'); break; case 'crm': include('content/crm.php'); break; case 'eventos': include('content/eventos.php'); break; case 'contact': include('content/contact.php'); break; default: include('content/introduccion.php'); break; } } else { include('content/introduccion.php'); } ?&gt; &lt;/section&gt; &lt;/article&gt; &lt;?php include('includes/footer.php'); ?&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p>The key is to make the script work only in <code>introduccion.php</code>, so the HTML shown in browser looks like this:</p> <pre><code>&lt;body&gt; &lt;div id="big_wrapper"&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script&gt;jQuery.get(source);&lt;/script&gt; &lt;?php include('includes/header.php'); ?&gt; &lt;article&gt; &lt;section&gt; &lt;!--&lt;script type="text/javascript" charset="utf-8" src="adobeEdge_animation.js"&gt;&lt;/script&gt;--&gt; &lt;script type="text/javascript" src="js/script.js"&gt;&lt;/script&gt; &lt;style&gt; .edgeLoad-adobeEdge_animation { visibility:hidden; } &lt;/style&gt; &lt;h2 lang="sp"&gt;Introducción&lt;/h2&gt; &lt;h2 lang="en"&gt;Introduction&lt;/h2&gt; &lt;div class="first_text"&gt; &lt;div id="Stage" class="texto_aim_web_marketing"&gt;&lt;/div&gt; &lt;p lang="sp"&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, rerum.&lt;/p&gt; &lt;p lang="sp"&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ullam, quod.&lt;/p&gt; &lt;p lang="en"&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eius, nostrum.&lt;/p&gt; &lt;p lang="en"&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eaque, vel.&lt;/p&gt; &lt;div class="first_text"&gt; &lt;p lang="sp" style="text-align: center;"&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolor quo ut quidem mollitia tenetur maxime.&lt;/p&gt; &lt;p lang="en"&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore, commodi natus quia voluptas iure libero.&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/section&gt; &lt;/article&gt; &lt;?php include('includes/footer.php'); ?&gt; &lt;/div&gt; &lt;/body&gt; </code></pre> <p>Here's my JavaScript (<strong>js/script.js</strong>)</p> <pre><code>function loadjsfile(filename){ var fileRef = document.createElement('script'); fileRef.setAttribute("type","text/javascript"); fileRef.setAttribute("charset","utf-8"); fileRef.setAttribute("src", filename); if (typeof fileRef!="undefined") document.getElementsByTagName("section")[0].appendChild(fileRef); } } $(document).ready(function(){ if ($(window).width() &gt; 640) { loadjsfile("myAnimation_edgePreload.js"); //dynamically load and add this .js file } }); $(window).resize(function(){ if ($(this).width() &gt; 640) { loadjsfile("myAnimation_edgePreload.js"); //dynamically load and add this .js file } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload