Load a JavaScript file dynamically and call a function from it

This is how you provide an embed code, which will load a JavaScript file dynamically into the website and call a function from inside the file with externally passed params.

Incoming search terms:


  • Amgad Fahmi

    You also can have a look on my project on Github https://github.com/amgadfahmi/scripty , it uses es6 custom tags

  • Thank you for this example. What I can’t figure out from this is: when will a readyState exist for the script , and when won’t it?

  • Jsx

    Hello, script.readyState was a non-standard implementation present in some older browsers. So that if-condition is only applicable for older browsers. script.readyState will never exist when run in modern browsers. script.onload is the standard and modern way to know when scripts are loaded.

  • Aha. Thanks for the info ๐Ÿ™‚