Feature request: attaching `EventListener` to `window` instead of `document`.
Some html events only occurs at the window level. E.g.: message. It could prove useful to add EventListeners for these kind of events. At the moment, when the EventListener has no children, it attaches to document by default. A possible implementation could add a variable which would specify the kind of object to attach to by default.
@fgoudreault Could you provide an example that could be used to reproduce? I've been tooling around in the Javascript side lately and would like to give this a shot for a patch.
Thanks!
@joebeeson Of course! A usecase would be to be able to listen to message events. For instance, you could have any message event posted in the window using:
function sendMsg() {
window.postMessage("Yoda"); // window.postMessage(payload, origin, transfer)
}
In order to receive this signal, one needs to define an event listener attached to the window (and not the document!). For instance:
window.addEventListener("message", receiveMsg)
One possible implementation would be to add a flag to attach the event listener to the window instead of the document here.
I think this is a good idea. I am wondering if there is a use case for attaching to the document rather than window at all? Otherwise, we could change the default to be window (if no components are specified as children). What do you think, @joebeeson @fgoudreault ?
I am not a big expert on events in html, but according to these docs, there are some events that fire only in the document such as the drop event (drag'n'drop) , full screen, touch events, etc. Therefore, I believe it could be warranted to listen to these events as well.