Re: Problem with prototype Event class and IE

Tom Gregory
Wed, 09 Aug 2006 15:09:08 -0000

It''s not Prototype''s problem. IE doesn''t pass the
event object to the
handler function like Firefox (or pretty much any other browser).

You can get around it in a couple of ways:
1. Check for the event object at the top of your function, if it''s
not there, grab window.event.
function (evt) {
     if (!evt) {evt = window.event;}
     // Do stuff
}

2. Use Prototype''s bindAsEventListener function, which ensures the
event object is always passed to the handler.
Behaviour.register({
       ''div'': function(element) { element.onclick =
show_clicked.bindAsEventListener(element); }
    });

On Aug 9, 2006, at 6:38 AM, Tim Bellinghausen wrote:

> Hi *,
>
> I have a problem with the prototype Event class and the Internet
> Explorer. The page is just some positioned divs and a p for debugging
> output. (It is used just for understanding some other IE difficulties)
> The javascript code used is the following:
>
>    function show_clicked(event) {
>       $(''DEBUG'').innerHTML +=
Event.element(event).id+" clicked<br /
> >";
>    }
>
>    Behaviour.register({
>       ''div'': function(element) { element.onclick =
show_clicked }
>    });
>
> Everything is fine in Firefox, but if I try this in IE it gives an
> error, when clicking on any div. The error message is
"''target'' is
> null
> or not an object" and refers to the following line in  prototype.js;
>
>   element: function(event) {
>     return event.target || event.srcElement;
>   },
>
> Inside the Event class. Has anybody a solution to this problem or at
> least an explanation, why this happens.
>
> Greets, Tim
>
> _______________________________________________
> Rails-spinoffs mailing list
> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs