W3C home > Mailing lists > Public > public-html@w3.org > September 2007

Re: load event for dynamic iframes - firing when changing the frame's location

From: Jon Barnett <jonbarnett@gmail.com>
Date: Wed, 5 Sep 2007 08:49:42 -0500
Message-ID: <bde87dd20709050649y1370e4ft47ddad83c9fc06b9@mail.gmail.com>
To: "Michael A. Puls II" <shadow2531@gmail.com>
Cc: public-html@w3.org

On 9/4/07, Michael A. Puls II <shadow2531@gmail.com> wrote:
> When you create an iframe with innerHTML or createElement and the
> iframe has an onload attribute set (or .onload = function or
> addEventListener), when the iframe is added to the document, the js in
> the onload attribute is executed in FF, Safari and Opera.
> Now, after the iframe is added to the document, if you change the
> location (via .src or .location or by submitting a form that targets
> the iframe, whether the js in the iframe's onload attribute fires
> again depends on what browser you're using.
> In FF and Safari, it is not fired again. In Opera it is.
> So, basically, FF and Safari do not fire a load event for the location
> change of dynamic iframes. Opera does.

Firefox does fire the load event after the location change.  For
example, modify your test case to change this line:
iframe.setAttribute("onload", "alert('load event for dynamic iframe fired)");
to this:
iframe.setAttribute("onload", "alert('load event for dynamic iframe
fired: ' + this.src)");

You'll see that Firefox is only showing one alert, and it's showing
the alert on the load event AFTER changing the .src attribute.  The
first load event never gets fired because your test case changes the
.src attribute before it gets a chance.

If you modify the test case to separate these events [1], you'll see
that they both get fired.

> Now, for changing the location of parsed iframes, Safari does the same
> as it does with dynamic ones and doesn't fire.  Firefox however, does
> fire and so does Opera.

Safari may have had the same issue here - you changed the iframe's src
before it was ever initially loaded.  Of course, then we get into the
question of whether window.onload should have been fired before the
iframe had initially loaded.  I haven't looked at that part of the
draft recently to see if it says anything about that.

Either way, we agree that the iframe.onload event should be fired when
iframe's location is changed (and the new resource has loaded) no
matter what, right?

> --
> Michael

<title>dynamic iframe</title>
window.onload = function() {
iframe = document.createElement("iframe");
iframe.setAttribute("onload", "alert('load event for dynamic iframe
fired: ' + this.src)");
<style>iframe {	width: 0; height: 0px; }
<p><button type="button" onclick="iframe.src = './';">Change Iframe's
Jon Barnett
Received on Wednesday, 5 September 2007 13:49:49 UTC

This archive was generated by hypermail 2.3.1 : Thursday, 29 October 2015 10:15:26 UTC