Anyone know how long window event listeners are supposed to persist?
My initial thoughts are that any attached to the document are probably lost after a page reload while those attached to the window object I would expect to persist over a page reload.
However testing seems to indicate that all event listeners are destroyed when the page is reloaded, is this correct?
Anyone know how long window event listeners are supposed to persist?
My initial thoughts are that any attached to the document are probably lost after a page reload while those attached to the window object I would expect to persist over a page reload.
However testing seems to indicate that all event listeners are destroyed when the page is reloaded, is this correct?
Share Improve this question asked Sep 17, 2016 at 15:06 NickCNickC 1,3635 gold badges16 silver badges23 bronze badges 01 Answer
Reset to default 18The listeners for an event on an element will persist as long as:
They are not removed.
The element continues to exist.
Reloading the page destroys the page's current elements and builds new ones from scratch, so event listeners don't survive that. (It also destroys the JavaScript environment that was associated with the page. So if the handlers were in that environment, they stop existing too.)