Created
November 18, 2018 12:55
-
-
Save NarHakobyan/1e59cc5fa912d9b5d0f08a365036b119 to your computer and use it in GitHub Desktop.
javascript dynamic script load
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
// 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