Open
Bug 500253
Opened 15 years ago
Updated 2 years ago
Event declared as <body onclick="foo()"> behaves differently than event declared as document.body.onclick=foo
Categories
(Core :: DOM: Events, defect, P5)
Tracking
()
NEW
People
(Reporter: justin.lebar+bug, Unassigned)
Details
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1pre) Gecko/20090624 Shiretoko/3.5pre
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1pre) Gecko/20090624 Shiretoko/3.5pre
If a page's body tag contains an onclick handler (e.g. <body onclick="foo()">), then listener is invoked upon any click within the browser window. If, however, another function sets document.body.onclick, (e.g. <body onload="document.body.onclick=foo">), then the click listener is invoked only when we click above the bottom of the page. If the page is too short to fill up the whole window, then clicking towards the bottom of the window will trigger a click event only if the click handler is defined as in the first case.
Neither of these behaviors seems better to me than the other (maybe HTML5 says something about what the right behavior is), but they probably should be consistent.
I think this is just one manifestation of the fact that FF registers handlers defined in a <body> tag on the window. Another, perhaps more concering manifestation is the fact that, if the listener is declared by "document.body.onclick=foo;", then we can unregister it by setting "document.body.onclick=null;". If, on the other hand, we define the listener in the body tag, we can unregister it only by setting "window.onclick=null"; in this case, "document.body.onclick=null" has no effect.
In this case, the correct behavior seems to be that document.body.onclick=null should disable the onclick handler, no matter how it was declared.
I've verified this behavior the latest 3.5rc (Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1) Gecko/20090616 Firefox/3.5) and the most recent nightly ( Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1pre) Gecko/20090624 Shiretoko/3.5pre).
Reproducible: Always
Updated•15 years ago
|
Component: General → DOM: Events
Product: Firefox → Core
QA Contact: general → events
Version: unspecified → Trunk
According to the spec we should never move onclick eventhandlers from the body to the window:
http://www.whatwg.org/specs/web-apps/current-work/?slow-browser#event-handler-attributes-on-elements,-document-objects,-and-window-objects
Reporter | ||
Comment 2•15 years ago
|
||
To be clear, there are basically two problems here:
* We move event handlers from the body to the window inappropriately (as we do with <body onclick="foo()">).
* We *don't* move event handlers defined as |body.onload = foo| to the window, as appropriate.
Comment 3•6 years ago
|
||
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046
Move all DOM bugs that haven’t been updated in more than 3 years and has no one currently assigned to P5.
If you have questions, please contact :mdaly.
Priority: -- → P5
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•