Skip to content

Instantly share code, notes, and snippets.

@NarHakobyan
Created November 18, 2018 12:55
Show Gist options
  • Save NarHakobyan/1e59cc5fa912d9b5d0f08a365036b119 to your computer and use it in GitHub Desktop.
Save NarHakobyan/1e59cc5fa912d9b5d0f08a365036b119 to your computer and use it in GitHub Desktop.
javascript dynamic script load
// Create script tag
const stripeScript = document.createElement('script');
//add necessary html attributes
stripeScript.setAttribute('type', 'text/javascript');
stripeScript.setAttribute('src', 'https://js.stripe.com/v3/');
// add listener for which will trigger when script will fully loaded
stripeScript.addEventListener('load', () => {
console.log(window['Stripe']);
});
// append to head tag of DOM
document.head.appendChild(stripeScript);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment