关闭浏览器弹出对话框事件onbeforeunload http://www.blogjava.net/jennyli/articles/82351.html

在点击浏览器关闭按钮关闭浏览器的时候,有时不希望它直接关闭,希望弹出对话框提示客户,这个时候就需要用到事件onbeforeunload,用法如下:
<script language="javascript">
<!--
function opCheckUnload(){
  if(g_blnCheckUnload){
    try{
      window.event.returnValue = "if close the window,the auto task will complete with document no update version";
    }catch(e){}
  }
}
-->
</script>

<body onbeforeunload="opCheckUnload();">
</body>

不过这种用法不支持firefox,因为firefox不支持window.event,所以本人改了一种方式,应用如下:
window.onbeforeunload = function() {
   if(g_blnCheckUnload){
     return("if close the window,the auto task will complete with document no update version!");
   }
}

这样几种浏览器都支持了,弹出对话框如下:


但这里有个问题,本来还没有解决的,我用的浏览器是中文版,但我做的系统是英文版,这个事件弹出来的窗口所显示的语言随浏览器,没有办法自己在javascript里设置。
原文地址:https://www.cnblogs.com/si812cn/p/1407587.html