3

I'm trying to find out browser compatibility for the event originalEvent. And looked in various places but couldn't find about it.

This answer's link also has no information.

I also checked in can i use but there's also no information.

So, I would like to know how much I'm safe to use originalEvent?

gacat
  • 116
  • 1
  • 13
  • I also thought that after searching. But that's not originalEvent but originalTarget. – gacat Apr 15 '20 at 03:59
  • 1
    `window.addEventListener('click', (e) => console.log(e.originalEvent));` gives me `undefined` in Chrome. Sounds not safe to use, whatever it is – CertainPerformance Apr 15 '20 at 04:00
  • Ah, I should just go to bed, I cannot read.... wait are you talking about libraries that wrap the event object?? – epascarello Apr 15 '20 at 04:01
  • 2
    As the answer linked in your question suggests, `originalEvent` is not a real thing. jQuery wraps it's events in it's own interface and hence provides the user access to 'original event' through the property `e.originalEvent` – Agney Apr 15 '20 at 04:02
  • The linked answer states it as a native event. And now I'm confused a little bit. – gacat Apr 15 '20 at 04:04
  • It is the "original event" object that they captured. They put a wrapper around it. So it is the vanilla js event object. – epascarello Apr 15 '20 at 04:04
  • @epascarello That's what I supposed to. But I'm looking for browser compatibility. – gacat Apr 15 '20 at 04:05
  • What do you mean browser compatibility? It is what jQuery sets. It is whatever the [event object](https://developer.mozilla.org/en-US/docs/Web/API/Event) is that the browser fired for that event – epascarello Apr 15 '20 at 04:06
  • Oh, it's not javascript core? Then, linked answer is not correct? That states native event. – gacat Apr 15 '20 at 04:06
  • It is the native JavaScript event..... it is what the original event was, they could have named it foobarEvent. – epascarello Apr 15 '20 at 04:07
  • @gacat No, it is correct, `event.originalEvent` is the native event object browsers provide when an event fires. – Teemu Apr 15 '20 at 04:07
  • @Teemu So, can I use safely? – gacat Apr 15 '20 at 04:08
  • As safely as any native feature, not all of them are standard, but `event.originalEvent` itself exists in all jQuery events. – Teemu Apr 15 '20 at 04:08
  • @Teemu Okay, thank you. – gacat Apr 15 '20 at 04:11

1 Answers1

1

Looking for the jQuery docs you can find this:

When the browser triggers an event or other JavaScript calls jQuery's .trigger() method, jQuery passes the handler an Event object it can use to analyze and change the status of the event. This object is a normalized subset of data provided by the browser; the browser's unmodified native event object is available in event.originalEvent.

Therefore this is not usable outside of a jQuery element as this is only to access the actual native event.

GMaiolo
  • 4,207
  • 1
  • 21
  • 37