Re:HTML event handler attributes: down the rabbit hole
by spiralx on Tuesday April 26, 2022 @10:19PM
(#31175536)
But window.event is deprecated as you can see here:
https://developer.mozilla.org/en-US/docs/Web/API/Window/even...
It's been around since IE 4 and is the "current event being handled by the site's code" so it's event inside the scope of an event handler and undefined anywhere else. That's definitely an anti-feature lol, maybe IE 4 didn't pass the event object into an event handler's synthetic function as an argument and window.event was a bodge to allow for <div onclick="alert(event.button)"> ?
Actually, I bet back then the code in the event handler attribute was just wrapped in eval() and executed, so you would need to have the event object in the global scope to be usable in the eval'd code.
Re:HTML event handler attributes: down the rabbit hole
by hnbad on Wednesday April 27, 2022 @04:49AM
(#31177764)
That is true, but also note that "deprecated" doesn't necessarily mean it's going away any time soon. The web platform is historically backwards compatible to a fault with the usual exceptions being mostly security-related (e.g. CORS) or "experimental" features that never saw widespread implementation.
The Event API is not deprecated: https://developer.mozilla.org/en-US/docs/Web/API/Event. In the posted examples the `event` object implements the Event interface.