Closed
Bug 52585
Opened 24 years ago
Closed 24 years ago
BODY's onload handler now called for each IMG loaded in the page.
Categories
(Core :: DOM: Core & HTML, defect, P2)
Core
DOM: Core & HTML
Tracking
()
People
(Reporter: jrgmorrison, Assigned: hjtoi-bugzilla)
References
Details
Attachments
(1 file)
1.06 KB,
text/html
|
Details |
Overview Description:
The BODY onload handler is now called once for the document, and
once for each IMG in and HTML page.
Steps to Reproduce:
1) Load the attachment, look in the console, wait for an alert.
Actual Results:
The test page has 10 images in it. The onload handler is called 11 times.
Expected Results:
The onload handler for HTML BODY is only supposed to be called when the
document is loaded. (Or for a FRAMESET, when all FRAMES have been loaded).
Reproducibility: always
Build Date & Platform Bug Found:
2000091312 win2k, but the mac/linux/win32 and I believe this started after
Sep07.
Additional Information:
I tried some old builds and narrowed this change in behaviour down to between
Sep 07 8am builds and Sep 08 8am builds, and then checked the Checkin logs.
This looks like it was your checkin for bug 22710, Heikki. I assume that the
'load' event is bubbling up and being handled by the BODY node's handler.
This
is not consistent with the HTML spec, and will play havoc with some Web pages
(if the functions have side effects).
Test Case:
<HTML><HEAD>
<script>
var gCount = 0;
function doOnLoad() {
if (document.getElementById)
dump('onload: ' + gCount + '\n');
gCount++;
}
setTimeout('alert("onload was called " + gCount + " times.")', 5000);
</script>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#003366" onLoad="doOnLoad();">
<p> A page with 10 images. Onload is called for the page and for each image
loaded. </p>
<IMG SRC="http://home.netscape.com/images/nc_cnnlogo.gif"><br>
<IMG SRC="http://home.netscape.com/images/nc_blue_navi2.gif"><br>
<IMG SRC="http://home.netscape.com/images/nc_text_navi.gif"><br>
<IMG SRC="http://home.netscape.com/images/nc_ns_lockup.gif"><br>
<IMG SRC="http://home.netscape.com/images/nc_tab0_top.gif"><br>
<IMG SRC="http://home.netscape.com/images/nc_tab0.gif"><br>
<IMG SRC="http://home.netscape.com/images/nc_todaysfeature.gif"><br>
<IMG SRC="http://home.netscape.com/images/nc_ha_search.gif"><br>
<IMG SRC="http://home.netscape.com/images/nc_ha_sportsnet.gif"><br>
<IMG SRC="http://home.netscape.com/images/nc_channels2.gif"><br>
</BODY></HTML>
Nom. nsbeta3, as this could be be mucking up a lot of DHTML pages,
and other consumers of onload events.
Reporter | ||
Comment 1•24 years ago
|
||
Assignee | ||
Comment 2•24 years ago
|
||
Yes, this is me. Hmm... maybe the image load event should not be allowed to
bubble then, even though I think it would be really handy if it DID bubble.
Besides, error event does bubble. A script can easily check what has been loaded
by doing
if (document == event.target) {
// This is document load
}
But, because this might break many pages I'll change it.
Status: NEW → ASSIGNED
Priority: P3 → P2
Reporter | ||
Comment 3•24 years ago
|
||
Perhaps what you could do is change the HTML onload code to do that check itself,
and let the image load event bubble normally. The 'onload' HTML attribute is
defined to only be listening for document related 'load' events, so it's OK
for it not to be listening for 'load' events from other targets.
Assignee | ||
Comment 4•24 years ago
|
||
I have a partially working solution in my tree. We discussed this with joki, and
I have now changed nsIPresShell::HandleEventWithTarget to take an additional
argument, event flags. I removed all the cases (6) which deleted the
CANT_BUBBLE/CANT_CANCEL event flags. We can now set the flags in the extra
argument, for example in the case of image load we can set it to not bubble. We
are now trusting the event flags argument that gets passed in to various event
handler functions.
As I said, this is working at least partially. The onload handler for the body
does no longer get called for the image load. However, if I add onload handler
for the image, the BODY's onload handler gets called twice, both for the
document load and image load. Doh! Clearly some debugging remains...
Comment 5•24 years ago
|
||
This is simply a must-fix for nsbeta3.
Assignee | ||
Comment 7•24 years ago
|
||
*** This bug has been marked as a duplicate of 52526 ***
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → DUPLICATE
The Mozilla chrome is also affected by this; see Bug 51211. It uses
addEventListener("load") under the assumption that only pages will fire load
events.
Even though the DOM Level 2 spec disagrees, I think it's probably appropriate
for image load events to bubble (frame load events bubble as well, by the
way...), and the chrome handlers should be changed. However for HTML
compatibility, the body onLoad handler should probably filter out non-document
loads.
You need to log in
before you can comment on or make changes to this bug.
Description
•