js 页面离开前触发事件

当前窗口载入新的dom文档前发生

1 window.onbeforeunload = function(event) { return confirm("确定离开此页面吗?"); 
原文地址:https://www.cnblogs.com/ProDoctor/p/6510453.html