Version: (using KDE Devel) Installed from: Compiled sources When a method is added as an event handler in KHTML, the scripting context of the method is passed in as the element who was the target of the event, rather than that of the window itself. For example - if I do this: myElement.onclick = function () { alert( "Element HTML is " + innerHTML ); } ... it *should not* work. The way to properly access the context element of an event, is by referencing the 'target' or 'currentTarget' properties of the passed in event, as such: myElement.onclick = function (e) { alert( "Element HTML is " + e.target.innerHTML ); } ... or in IE land ... myElement.onclick = function () { alert( "Element HTML is " + window.event.srcElement.innerHTML ); } While I cannot find the specification for how this *should* behave, in either the W3C DOM spec or the ECMA specs, this behaviour is different from both Internet Explorer and Gecko, so could break many scripts which expect certain properties to be either global veriables, or properties of the window object. I recently ran into this when trying to access the property 'parent' of the global window object inside a function whose source also had a 'parent' property. Test case attached. When you click on 'This is the body', you should get a scripting error saying that the variable is undefined. In KHTML, you get an alert of the body innerHTML.
Created attachment 10048 [details] Test Case
Hmm, my mail to 101202-done@bugs.kde.org didn't seem to close the bug? CVS commit by faure: Move "pushing element/form/doc onto the scope" from JSEventListener::handleEvent to JSLazyEventListener::handleEvent so that it only happens with listeners set from html attributes, not from JS - in which case the function already got a correct scope when created. Testcase: events/eventhandlerscope.{html,js} M +8 -0 ChangeLog 1.398 M +22 -11 ecma/kjs_events.cpp 1.93