0

Is there any way, using prototype or other means, to make events copy themselves into the global space (window.event)?

My problem is that I'm using a remote script that does not pass me the event object to my callbacks. Chrome and IE always have access to event and event window.event, but FireFox has neither, unless passed (and set) explicitly, so I was wondering if there was a way to prototype event objects to copy themselves into the global space.

bearfriend
  • 10,322
  • 3
  • 22
  • 28

2 Answers2

1

You can attach event listeners to the window object directly by doing the following:

window.addEventListener('click', function (e) {
   // here's where something useful happens...
   alert(e);
}, false);

See this good post for information on event bubbling. What is event bubbling and capturing? Hope that helps.

Andy

Community
  • 1
  • 1
Andy
  • 2,709
  • 5
  • 37
  • 64
0

In my particular case, the following line gets the event object in FireFox properly:

var event = event || window.event || arguments.callee.caller.arguments[0];

I went digging and found it there. For anyone in a similar situation that this doesn't work for, look through the whole arguments.callee.caller.arguments array, and if it's not there, refer to Andy's answer, where you can set window.event or any other global variable to the event object. That should work no matter what.

bearfriend
  • 10,322
  • 3
  • 22
  • 28