Created
November 6, 2012 04:02
-
-
Save mikermcneil/4022473 to your computer and use it in GitHub Desktop.
Get jQuery on a page that doesn't have it
This file contains hidden or 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
| // Example usage: | |
| getjQuery(function (e) { | |
| // jQuery loaded successfully! | |
| }); | |
| // Get jQuery on a page that doesn't have it, | |
| // perhaps in order to engage in some laid-back hacking | |
| function getjQuery(callback) { | |
| loadScript("https://stripe.com/javascripts/jquery.js",callback); | |
| } | |
| // loadScript (https://gist.github.com/4023991) | |
| function loadScript(src,optionalCallback) { var s = document.createElement("script"); s.type = "text/javascript"; s.src = src; var context = document.getElementsByTagName('script')[0]; context.parentNode.insertBefore(s, context); s.async=true; s.addEventListener('load',optionalCallback); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment