Skip to content

Instantly share code, notes, and snippets.

@AdamSaleh
Created August 31, 2015 12:57
Show Gist options
  • Save AdamSaleh/0615769ffc120660a381 to your computer and use it in GitHub Desktop.
Save AdamSaleh/0615769ffc120660a381 to your computer and use it in GitHub Desktop.
Testing javascript injection
var jqueryInjector = function(callback) {
jqueryUrl = 'https://code.jquery.com/jquery-1.11.3.min.js';
if (typeof jQuery == 'undefined') {
var script = document.createElement('script');
var head = document.getElementsByTagName('head')[0];
var done = false;
script.onload = script.onreadystatechange = (function() {
if (!done &&
(!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
done = true;
script.onload = script.onreadystatechange = null;
head.removeChild(script);
callback();
}
});
script.src = jqueryUrl;
head.appendChild(script);
} else {
callback();
}
}
Then when you run
return this.execute(
jqueryInjector,
[],cb);
You can be sure that you have jQuery aviable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment