最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How long do .WIndow Event Listeners persist - Stack Overflow

programmeradmin2浏览0评论

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 0
Add a ment  | 

1 Answer 1

Reset to default 18

The listeners for an event on an element will persist as long as:

  1. They are not removed.

  2. 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.)

发布评论

评论列表(0)

  1. 暂无评论