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.
I have no issue with the SetSrc function, I use the Form OnLoad event.
Some example code
// Get MAT IFrame control
var MATRepiFrame = Xrm.Page.ui.controls.get("IFRAME_MATGraph");
//Setup the URL
MATTargetUrl = serverUrl + '/crmreports/viewer/viewer.aspx?action=run&context=records&id=%7b092E3880-8266-E711-80DD-005056BD212E%7d&recordstype=1&records=' + accountId;
//Set the source
MATRepiFrame.setSrc(MATTargetUrl);
For more details see this webpage here: https://msdn.microsoft.com/en-us/library/gg328034.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With