Skip to content

Instantly share code, notes, and snippets.

@mikermcneil
Created November 6, 2012 04:02
Show Gist options
  • Select an option

  • Save mikermcneil/4022473 to your computer and use it in GitHub Desktop.

Select an option

Save mikermcneil/4022473 to your computer and use it in GitHub Desktop.
Get jQuery on a page that doesn't have it
// 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