'Identification of 'event' in Mozilla Firefox
The following markup works pretty well in Chrome and IE, but not in Firefox:
<!Doctype html>
<html>
<head>
<title>Testing Events</title>
<script>
function HandleInput() {
console.log(event.which);
}
</script>
</head>
<body>
<label id="lblName">Please Enter You Name:</label>
<input id="txtName" type="text" onkeypress="HandleInput()"></input>
</body>
</html>
Running this in Firefox leads to the following error message in the console:
ReferenceError: event is not defined.
I do know the solution to this; passing the event object in the function call.
But I would like to know why is it that this happens.
Solution 1:[1]
It happens because window.event is a nonstandard IE-ism which some other browsers copied but Firefox did not. And the code you show is depending on there being an event property on the global, which means on the window.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Boris Zbarsky |
