handleEvent DOM API breakage
David Faure
faure at kde.org
Sun Oct 19 01:41:19 CEST 2003
On Saturday 18 October 2003 03:28, Darin Adler wrote:
> I was fixing a bug with an element that looked like this:
>
> <body onLoad="this.document.myForm.submit();">
>
> The value of "this" was the document in KHTML, but the window in other
> browsers.
Yes, but this is apparently a special case for onLoad.
After testing in Mozilla, IE (5 and 6), it is apparent that onLoad is treated
like a window event, setting "this" to "window" indeed.
However for any other event, like e.g. onmousedown:
In Mozilla: "this" is the window, so this.document works.
In IE5/6: "this" is the body, so this.document works there too.
In KHTML: "this" is the body. I guess this gets broken by your Safari change,
it would set it to the window in that case. I don't believe this is a good idea,
since it makes much more sense for it to be the body, given that it's a body
event; and given that currentTarget can then point to the body (which is a DOM node)
whereas Window isn't one. I don't see how it can be DOM-compliant to have
currentTarget point to a non-DOM object, like Mozilla does.
(My test on event.currentTarget showed that it's the window in Mozilla,
and non-implemented in IE5/6)
Conclusion: <body onload> (and probably onunload) really appears to be treated
as a special case, as if it was an event on the window instead of one on the
body. Other events, though, should be treated as coming from the body.
So we still need a fix/hack in KHTML somewhere to set this==window for onload,
but only in that case. We simply can't set currentTarget to window like Mozilla
since it's not a DOM node.
Before I look into patching this - any objections?
PS: testcase attached.
--
David FAURE, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/mailman/private/khtml-devel/attachments/20031019/ea2f4ded/body-events-this.html
More information about the Khtml-devel
mailing list