Last active
June 23, 2016 06:43
-
-
Save thanhpk/9aa549457b679834eead2706f740a972 to your computer and use it in GitHub Desktop.
Add jQuery to a webpage using google console programmatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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