Iframe onload triggers before content has fully loaded-help!

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
nazg
Forum Newbie
Posts: 12
Joined: Thu Dec 03, 2009 11:52 am

Iframe onload triggers before content has fully loaded-help!

Post 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.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

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

Post by daedalus__ »

im not sure if you can. i thought onload meant when an element is ready in the dom.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

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

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
nazg
Forum Newbie
Posts: 12
Joined: Thu Dec 03, 2009 11:52 am

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

Post 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.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

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

Post by daedalus__ »

what about frame.contentWindow.onload or contentwindow.document

ill play around in a few mintues
Post Reply