tags:

views:

21

answers:

2

I dynamically am changing the location and src of an iframe.

Is there an event that will tell me when the page i just put has loaded from javascript?

Basically I want to append something to the page but first need to know that everything is loaded.

+3  A: 

You may want to use the onLoad event, as in the following example:

<iframe src="http://www.google.com/" onLoad="alert('Test');"></iframe>

The alert will pop-up whenever the location within the iframe changes, including the first time it finishes loading. However note that this may not work with some older browsers like IE5 and early Opera. (Source)

Daniel Vassallo
A: 

Something like this:


frame.src = url;
if (frame.addEventListener) {
    frame.addEventListener("load", function () {
        *insert code here*
    }, false);
} else if (frame.attachEvent) {
    frame.attachEvent("load", function () {
        *insert code here*
    }
}

Note that this code is not tested, and may not work.

BTW, onload, onclick, and such are outdated, mainly because they can only handle one event listener, unless you build your own (bad for productivity).

Hello71