anony_root anony_root - 11 months ago 34
Javascript Question

Why FF says that window.event is undefined? (call function with added event listener)

I have a trouble in this part:

var ex = {
exampl: function(){
var||window.event.srcElement; // here
alert(ref.innerHTML); // (example)

This function is called this way:


Only Firefox says that
isn't defined...

I don't know what to do, to make it work. It works very well in webkit browsers and opera (I can't check it in MSIE and I don't care about it).

Why does it happen?


try getting the event using the parameter passed (named e in this case). i tested this and both window.event and the e is supported in chrome.

try checking for both, whichever exists

var ex = {
  exampl: function(e){


    //check if we have "e" or "window.event" and use them as "evt"
    var evt = e || window.event