Set IFRAME's src on form load, avoiding load-race

Viewed 1145

I'm considering using an IFRAME in a form, and would like to know what's the correct way to avoid the traditional IFRAME load-race problem.

I thought I can simply set the IFRAME's src with a call inside the form's OnLoad event handler, since (source):

The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images, scripts, links and sub-frames have finished loading.

but MSDN says (bold added):

Avoid using the OnLoad event. IFRAMES and web resources load asynchronously and the frame may not have finished loading before the Onload event script finishes. This can cause the src property of the IFRAME or web resource you have changed to be overwritten by the default value of the IFRAME or web resource URL property.

If that so, what is the correct way to set the IFRAME's src?

Note: I thought about using the IFRAME's OnReadyStateComplete event, meaning: Having an event handler in the form's script, set src when event fires, and use a flag to indicate that it was set (so that I won't enter an infinite load loop), but it seems like a bypass.

1 Answers
Related