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

后端 未结 3 828
北海茫月
北海茫月 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:08

    The load event for script elements was introduced in HTML5, prior to that it was only available for frameset and body elements (though most browsers also implemented it for img elements too). So if you want to support earlier browsers you'll need to be creative.

    One solution is to put a function call at the top of the script to say that the script has been loaded, as the browser should not execute any code in the script until it's loaded in its entirety.

    Another is to insert a second script with the "I'm loaded" function or flag immediately after the first in the presumption that the second will not be executed until the first has been loaded and executed.

提交回复
热议问题