Page 1 of 1

Iframe onload triggers before content has fully loaded-help!

Posted: Wed Dec 30, 2009 12:55 pm
by nazg
I have searched the web and found many people with the same problem but no solution that works.
I have an Iframe containing cross-domain content and I have a resize function that resizes the frame using height and width property of the iframe content. However, onload triggers the resize function too early, before all the content has loaded inside the frame so the frame is resized to the wrong size. I have tried using readyState, ready, (iframe object).onload = somefunction, so on and so forth. My code works if I use the setTimeout function to delay the resize, however the loading time varies across browser and servers and personal bandwidth (probably) and so I am looking for away I could find out when the content in my iframe has FULLY loaded into the frame.

Re: Iframe onload triggers before content has fully loaded-help!

Posted: Wed Dec 30, 2009 1:04 pm
by daedalus__
im not sure if you can. i thought onload meant when an element is ready in the dom.

Re: Iframe onload triggers before content has fully loaded-help!

Posted: Wed Dec 30, 2009 2:02 pm
by omniuni
Daedalus is right. Essentially, onLoad will trigger as SOON as the element is loaded. You could try adding a trigger script to the bottom of the page, though. Just put it as the very last thing in the code before the closing </body> tag. Remove the onload you have currently and use that instead. Add a 200ms delay just to not bombard the browser, and you should be good to go.

Re: Iframe onload triggers before content has fully loaded-help!

Posted: Wed Dec 30, 2009 2:40 pm
by AbraCadaver
As others have said, onload for the iframe will fire when the iframe object is loaded, not its content. For this to work you will need the onload in the body tag of the content that is being loaded into the iframe.

Re: Iframe onload triggers before content has fully loaded-help!

Posted: Wed Dec 30, 2009 2:44 pm
by nazg
To abracadaver: wait so would frame.contentWindow.body.onload = somefunction; work??

update: nope doesnt work; frame.contentWindow.body.onload = null. But now I am starting to wonder if any document objects have events listeners already attached to them.

Re: Iframe onload triggers before content has fully loaded-help!

Posted: Wed Dec 30, 2009 3:38 pm
by daedalus__
what about frame.contentWindow.onload or contentwindow.document

ill play around in a few mintues