how to check the script element load event accross browser without jquery

后端 未结 3 829
北海茫月
北海茫月 2020-12-12 02:24

I have to do the cross-domain ajax,so I try the jsonp.

Then I will have to add the script element dynamiclly to the page,however I can not check its sta

3条回答
  •  我在风中等你
    2020-12-12 03:15

    For IE, think of alternate ways to check load has happened, e.g. in your script file add the line

    script_myScriptUniqueName_loaded = true;
    

    and then in the dynamic add, if script.onload is not null (before setting a callback) use window.setInterval to check for existance of script_myScriptUniqueName_loaded, with a timeout to throw error, and if exists call callback.
    Remember to do window.clearInterval when you're done.

提交回复
热议问题