Home  >  Article  >  Web Front-end  >  判断页面是关闭还是刷新的js代码_基础知识

判断页面是关闭还是刷新的js代码_基础知识

WBOY
WBOYOriginal
2016-05-16 19:20:001005browse
标签只有onload\onunload\onbeforeunload事件,而没有onclose事件。不管页面是关闭还是刷新都会执行onunload事件。如何捕捉到页面关闭呢? 

    页面加载时只执行onload

    页面关闭时只执行onunload

    页面刷新时先执行onbeforeunload,然后onunload,最后onload。这样我们可以在onbeforeunload中加一个标记,在onunload中判断该标记,即可达到判断页面是否真的关闭了。


 
  判断页面是关闭还是刷新
 

 
  
 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn