捕捉浏览器的刷新与关闭 兼容ie、ff

<script language="javascript">
var MSG_UNLOAD="确定离开?";
var UnloadConfirm = {};

//启用监听浏览器刷新、关闭的方法
UnloadConfirm.set = function(confirm_msg){
    window.onbeforeunload = function(event){
        event = event || window.event;
        event.returnValue = confirm_msg;
    }
}

//关闭监听浏览器刷新、关闭的方法
UnloadConfirm.clear = function(){
    window.onbeforeunload = function(){};
}
UnloadConfirm.set(MSG_UNLOAD);
</script>

你可能感兴趣的:(浏览器,IE)