Skip to content

Instantly share code, notes, and snippets.

@thanhpk
Last active June 23, 2016 06:43
Show Gist options
  • Save thanhpk/9aa549457b679834eead2706f740a972 to your computer and use it in GitHub Desktop.
Save thanhpk/9aa549457b679834eead2706f740a972 to your computer and use it in GitHub Desktop.
Add jQuery to a webpage using google console programmatically
var loadjQuery = function(cb){
if(typeof(jQuery) == 'undefined'){
var scr = document.createElement('script');
scr.setAttribute('type', 'text/javascript');
scr.setAttribute('src', 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js');
if(scr.readyState){
scr.onreadystatechange = function(){
if(scr.readyState === 'complete' || scr.readyState === 'loaded'){
scr.onreadystatechange = null;
if(cb === 'function'){
args = [].slice.call(arguments, 1);
cb.apply(this, args);
}
}
};
}
else {
scr.onload = function(){
if(cb === 'function'){
args = [].slice.call(arguments, 1);
cb.apply(this, args);
}
};
}
var head = document.getElementsByTagName('head')[0];
head.insertBefore(scr, head.firstChild);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment