I have a trouble in this part:
var ex = { exampl: function(){ var ref=window.event.target||window.event.srcElement; // here alert(ref.innerHTML); // (example) } }
This function is called this way:
document.body.childNodes[0].addEventListener('mouseover',ex.exampl,true);
Only Firefox says that window.event
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?
If your event listener not working is dependent on some logic, whether it's about which element it'll listen on or if it's registered at all, the first step is to check that the listener is indeed added to the element. Using a breakpoint in the developer tools , a logpoint or console.
You can add event listeners to any DOM object not only HTML elements. i.e the window object. The addEventListener() method makes it easier to control how the event reacts to bubbling.
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){ console.log(window.event); console.log(e); //check if we have "e" or "window.event" and use them as "evt" var evt = e || window.event } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With