No worries. I'm not entirely surprised return false didn't work. Did
you try Event.stop(event)? I'd give it no more than 50/50 odds...

-- T.J. :-)

On Jul 18, 5:45 pm, orbiter <[email protected]> wrote:
> "return false" didn't work but the timeout method did. Thanks for the
> help.
>
> On Jul 18, 9:38 am, orbiter <[email protected]> wrote:
>
>
>
> > Thanks, that explains a lot. I do most of my coding on firefox and
> > chrome and IE always throws me for a loop. I'll go with "return false"
> > and let you know how it goes.
>
> > On Jul 18, 8:48 am, "T.J. Crowder" <[email protected]> wrote:
>
> > > Hi,
>
> > > So basically you're replacing a DOM0 handler (the onclick attribute)
> > > with a DOM2 handler (via #observe) the first time it's clicked. My
> > > guess based on what you're observing is that IE8 fires DOM0 handlers,
> > > and then goes and fires any DOM2 handlers the element has. That
> > > doesn't actually surprise me much. :-) And so since your DOM0 handler
> > > sets up the DOM2 handler, when the DOM0 handler returns there's a DOM2
> > > handler there waiting to be called -- so IE calls it.
>
> > > Two possible ways I can see working around that behavior (which I
> > > wouldn't call a bug):
>
> > > 1. Stop the DOM0 event, probably by adding a return to your button
> > > element's onclick attribute (e.g., "return original_handler.bind(this)
> > > (event);" rather than just "original_handler.bind(this)(event)") and
> > > then return false from original_handler. Or you might try
> > > Event.stop(event); One or both of those may tell IE not to fire its
> > > DOM2 handlers.
>
> > > 2. Wait for the event to complete before hooking up the DOM2 handler.
> > > This has the inherent danger that someone clicking *very quickly*
> > > could click during the brief interval when there's no handler
> > > attached. It would be fairly unlikely. You'd replace your current
> > > observe call with something looking like this:
>
> > >     var self = this;
> > >     setTimeout(function() {
> > >         self.observe('click', newCallback);
> > >     }, 0);
>
> > > Although we've passed 0ms for the delay there, browsers typically do
> > > delays in the ~10ms range.
>
> > > HTH,
> > > --
> > > T.J. Crowder
> > > Independent Software Consultant
> > > tj / crowder software / comwww.crowdersoftware.com
>
> > > On Jul 18, 7:35 am, orbiter <[email protected]> wrote:
>
> > > > I have a button with an onclick callback that creates a closure and
> > > > uses Element.observe to clear the old callback and set the closure as
> > > > the new one. Here's the pseudo code:
>
> > > > <button onclick='original_handler.bind(this)(event)'>button</button>
>
> > > > function original_handler(event) {
> > > >   //do some stuff on the first click
>
> > > >   //now clear the original handler and set the new one
> > > >   this.writeAttribute({onclick:null});
> > > >   //create the newCallback
> > > >   function newCallback(event) {
> > > >     //do some new stuff when we click the second time
> > > >   }
> > > >   this.observe('click',newCallback);
>
> > > > }
>
> > > > Everything works fine in firefox and chrome but in IE8 when the new
> > > > callback
> > > > is set IE8 actually calls the function and messes everything up. So
> > > > instead of
> > > > click->call original_handler->set newCallback what I get is
> > > > click->call original_handler->set newCallback->call newCallback which
> > > > is not
> > > > what I want at all. Any advice on how to fix the situation.

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to