- 根据页面关闭时的事件判断
https://blog.csdn.net/u010175124/article/details/9092899
页面加载时只执行onload
页面关闭时只执行onunload
页面刷新时先执行onbeforeunload,然后onunload,最后onload
1 | <html> |
根据 performance.navigation.type判断
https://www.zhihu.com/question/29036668
0表示从链接进去,1表示刷新根据window.name判断
https://www.zhihu.com/question/29036668type 1
2
3
4
5
6
7window.onload = function() {
if (window.name == "") { // 直接进来才是空的
alert('直接进来');
}
window.name = "test"; // 刷新当前页面,window.name并不会销毁
};
</script>