Dynamically load external javascript file, and wait for it to load - without using JQuery

后端 未结 3 2030
南旧
南旧 2020-12-01 03:14

I\'m trying to dynamically load an external .js file (according to an input I get from the user). Currently my code looks like this:

function createScript(sr         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 03:50

    One of the best patterns to use here is to use addEventListener to listen for a custom event such as "MyScriptLoaded". Then, modify your included script to fire this event as its last action. This will ensure that you take action only after the new script has fully loaded.

提交回复
热议问题