HighDots Forums  

Re: IE6 and Mozilla loosing onclick event

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: IE6 and Mozilla loosing onclick event in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Yann-Erwan Perio
 
Posts: n/a

Default Re: IE6 and Mozilla loosing onclick event - 05-19-2004 , 06:54 PM






Pavils Jurjans wrote:

Quote:
Although body has onclick handler, it is not triggered when clicked on
the red area. This happens only in cases when the HTML that contains
tag with the onclick attribute which received the event, is overwriten
with a new value.
You're playing with on-the-edge events aspects, which aren't supported
by Mozilla/IE (although successfully implemented by Opera 7). According
to the DOM Events Specification, the body onclick handler should indeed
be triggered.

<URL:http://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/events.html>

<QUOTE>
The target's ancestors are determined before the initial dispatch of the
event. If the target node is removed during the dispatching, or a
target's ancestor is added or removed, the event propagation will always
be based on the target node and the target's ancestors determined before
the dispatch.
</QUOTE>


What probably happens with IE/Mozilla is that the event flow link isn't
saved before the event dispatch; we can reasonably assume that there's
no link at all, and that the browsers just follow the DOM hierarchy
(parentNode/childNodes) to process the event flow - when the target is
removed from the tree, the parentNode property is set to null so the
event cannot bubble toward the root element.

Quote:
Perhaps somebody has better
idea?
What about adding the listener on the parent node, or change only the
node value, not the node itself?


HTH,
Yep.


Reply With Quote
  #2  
Old   
Pavils Jurjans
 
Posts: n/a

Default Re: IE6 and Mozilla loosing onclick event - 05-20-2004 , 04:44 AM






Hello, Yann-Erwan

You explain this well. This really could be what's happening.
Currently I overcame this, replacing the event handler with function,
that calls window.setTimeout(originalFunction, 0). Now
document.onclick is properly called and then also original function is
handled. It is possible also to save the original event data, so the
only problem is that document.onlcick is now fired before the function
that was supposed to be the original inner tag trigger. But in my
design, that makes no difference.

Quote:
What about adding the listener on the parent node, or change only the
node value, not the node itself?
In my actual design, the listener tag is much more levels deeper, so
these approaces don't help here. I am working on standardized
framework for client-side DHTML controls, that may have popups and
then some clicking is done on those popups. I handle the clicks on the
popups, but this action mey requere redrawing of the popup HTML, so
there is this on-the-edge event thing. I need to handle
document.onclick, because that helps to determine wether user has
clicked outside of active popup, and thus close it.

Thanks,

Pavils


Reply With Quote
  #3  
Old   
Yann-Erwan Perio
 
Posts: n/a

Default Re: IE6 and Mozilla loosing onclick event - 05-20-2004 , 05:10 AM



Pavils Jurjans wrote:

Quote:
Currently I overcame this, replacing the event handler with function,
that calls window.setTimeout(originalFunction, 0).
How frightening:-) Browsers are event-based, using setTimeout this way,
even if this works, is just a hack - you might suffer a hell in
maintenance, Pavils.

This seems to be a conception issue; if you're ready to accept a global
handler (like your setTimeout thing suggests), then what about just
using document.onclick as a controller, which would then study the
target and redirect to appropriate actions?

document.onclick=function(evt){
var target;
evt=evt||window.event;
target=evt.target||evt.srcElement;
while(target.nodeType!=1) target=target.parentNode;
switch(target.id) {// or target.className, or target.<expando>
case "foo1": doFoo1.call(target, evt); break;
case "foo2": doFoo2.call(target, evt); break;
case "foo3": doFoo3.call(target, evt); break;
default:break;
}
}

Quote:
I am working on standardized
framework for client-side DHTML controls, that may have popups and
then some clicking is done on those popups. I handle the clicks on the
popups, but this action mey requere redrawing of the popup HTML, so
there is this on-the-edge event thing.
Hmm then I really don't see why adding the listener on a specific DIV
wrapper wouldn't work:

<div onclick="...">
<div id="popupToBeRedrawned">

</div>
</div>


Anyway, your app seems to be quite complicated, so that's just
suggestions:-)


HTH
Yep.


Reply With Quote
  #4  
Old   
Pavils Jurjans
 
Posts: n/a

Default Re: IE6 and Mozilla loosing onclick event - 05-20-2004 , 10:00 AM



Hello,

Quote:
How frightening:-) Browsers are event-based, using setTimeout this way,
even if this works, is just a hack - you might suffer a hell in
maintenance, Pavils.
That's true, I'm no less scared, too So I am looking for decent
solution

Quote:
then what about just using document.onclick as a controller, which would then study the target and redirect to appropriate actions?
That's actually a good idea. I'm just being somewhat conservative and
wanting to use basic event handlers, located in tag attributes.
Surely, there's no need to be so restrictive, so I'll try out how to
handle all this with single document.onclick handler. In fact, I wrote
a small class that enables multiple listener functionality, something
that IE is missing. Now I can subscribe my function to a certain
event, and there can be many such subscribers. That gives some freedom
in handling events coming from multiple controls.

Quote:
Hmm then I really don't see why adding the listener on a specific DIV
wrapper wouldn't work:

div onclick="..."
div id="popupToBeRedrawned"

/div
/div
Well, no need for that anymore, as I'll redo the event handling so
that it's always document.onclick that get's called.

Regards,

Pavils


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.