开发者

Check if 'onload' would have fired already?

开发者 https://www.devze.com 2022-12-23 23:33 出处:网络
I have a situation where I\'d like to set an onload handler for a script element, but it is possible that the script element has already loaded before I do so.If it\'s already loaded, I\'d like to det

I have a situation where I'd like to set an onload handler for a script element, but it is possible that the script element has already loaded before I do so. If it's already loaded, I'd like to detect that and run my handler immediately.

What would be a reliable way of checking a script element's onload state after t开发者_C百科he fact?

BTW I know that IE uses readyState instead of an onload event so I don't need help for that.


I don't believe that you reliably know this-- if you miss an event, then you've missed it. The simplest solution if you really can't know whether the script has already been loaded is to have the bottom of the script set some global flag indicating that it's been loaded; then you can check that, and set your onload handler if it's not present.

0

精彩评论

暂无评论...
验证码 换一张
取 消