js监听浏览器,关闭,刷新(兼容IE6+,Firefox,Chrome,Safari)

http://www.foolerp.com/knowledge-view-136.html

js阻止浏览器关闭 刷新、js监听浏览 关闭 刷新;对Alt+F4 、右键关闭 都起作用

var UnloadConfirm = {};
UnloadConfirm.MSG_UNLOAD = "数据尚未保存,离开后可能会导致数据丢失\n\n您确定要离开吗?";
UnloadConfirm.set = function(a) {
    window.onbeforeunload = function(b) {
        b = b || window.event;
        b.returnValue = a;
        return a
    }
};
UnloadConfirm.clear = function() {
    fckDraft.delDraftById();
    window.onbeforeunload = function() {}
};
UnloadConfirm.set(UnloadConfirm.MSG_UNLOAD);
js 阻止浏览器刷新 关闭、js监听浏览 关闭 刷新 兼容IE6+ Firefox Chrome Safari

你可能感兴趣的:(JS)