thebeast22
thebeast22

Reputation: 103

Negate an external script dynamically

I have a dynamic landing page that loads its content based on a parameter, this landing page has external scripts.
Now I have a condition that if met, it will negate or not execute an external script. Is that possible?

The external script has a lot of function there that is running on load, but I don't need it if the condition is met.

Let's say:

var k = aa;
if(k == "aa") {
    // run something
} else {
    // negate an external script
}

Upvotes: 0

Views: 62

Answers (1)

TimoStaudinger
TimoStaudinger

Reputation: 42460

If you have change access to the external script, then include the check into the script directly and always execute it.

If not, jQuery's getScript() function could be an option:

Load a JavaScript file from the server using a GET HTTP request, then execute it.

$.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {
  console.log( data ); // Data returned
  console.log( textStatus ); // Success
  console.log( jqxhr.status ); // 200
  console.log( "Load was performed." );
});

Upvotes: 1

Related Questions