function exit()
{
alert('确定要离开吗?');
}想在关闭窗口、点击页面上的链接离开该页时,调用上面的这个方法。注意:刷新页面时不调用最好是兼容各个浏览器的。

解决方案 »

  1.   

    window.unonload = function(){alert('确定要离开吗?');}
      

  2.   

    参考:
    http://topic.csdn.net/u/20080705/22/a47c894e-4adb-4a65-b6a0-09100361122a.html
      

  3.   

    刷新也会触发onunload事件的
      

  4.   

    转:
    <script language="javascript">
    window.onbeforeunload = function()  //author: meizz
    {
      var n = window.event.screenX - window.screenLeft;
      var b = n > document.documentElement.scrollWidth-20;
      if(b && window.event.clientY < 0 || window.event.altKey)
        {
            alert("是关闭");
      //  window.event.returnValue = "www";  //这里可以放置你想做的操作代码
        }
      else
        {
         alert("是刷新");
        }}
    </script>
      

  5.   

     
    window.unonload = function(){
      window.confirm("单击“确定”离开。单击“取消”终止");
    }