js 监控浏览器关闭(完美兼容chrome & ie & fire fox)

 1 var UnloadConfirm = {};
 2 UnloadConfirm.MSG_UNLOAD = "数据尚未保存,离开后可能会导致数据丢失\n\n您确定要离开吗?";
 3 UnloadConfirm.set = function(a) {
 4     window.onbeforeunload = function(b) {
 5         b = b || window.event;
 6         b.returnValue = a;
 7         return a
 8     }
 9 };
10 UnloadConfirm.clear = function() {
11     fckDraft.delDraftById();
12     window.onbeforeunload = function() {
13     }
14 };
15 UnloadConfirm.set(UnloadConfirm.MSG_UNLOAD);

就是在ie浏览器  稍微有些敏感了. 

你可能感兴趣的:(chrome)