码迷,mamicode.com
首页 > Web开发 > 详细

JS——浏览器关闭事件

时间:2018-07-21 18:29:28      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:turn   eve   list   his   url   pop   load   function   fun   

onbeforeunload

  • 关闭或刷新浏览器会触发此事件
window.onbeforeunload = function(ev) {       
    return true;
};

popstate

  • 当点击浏览器后退按钮会触发此事件

  • 基本上不用这个事件,vue 框架可以帮助代替这个事件

window.history.pushState("123", null, document.URL);
window.addEventListener("popstate", function() {
    _this.isMsgShow = true;
    history.pushState("123", null, document.URL);
});

JS——浏览器关闭事件

标签:turn   eve   list   his   url   pop   load   function   fun   

原文地址:https://www.cnblogs.com/cnloop/p/9347481.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!