javascript如何关闭浏览器事件-LMLPHP

本教程操作环境:windows7系统、javascript1.8.5版,DELL G3电脑。

javascript关闭浏览器事件的方法:

1、onbeforeunload

关闭或刷新浏览器会触发此事件

示例代码

window.onbeforeunload = function(ev) {       
    return true;
};
登录后复制

2、popstate

示例代码

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

以上就是javascript如何关闭浏览器事件的详细内容,更多请关注Work网其它相关文章!

09-13 01:07