js监听浏览器,关闭,刷新

//浏览器关闭或刷新事件
function bindCloseBrowser() {
    var a = "注意!!
您即将离开页面!离开后可能会导致数据丢失

您确定要离开吗?";
    window.onbeforeunload = function (b) {
        b = b || window.event;
        b.returnValue = a;
        return a
    }
}
原文地址:https://www.cnblogs.com/hllive/p/6225845.html