if(confirm()) {
  close here!
} else {
  ...
}

解决方案 »

  1.   

    我是这么写的:
    ...
    <body onbeforeunload="clearCookie()">
    .
    .
    .
    <script lanaguage="javascript">
    function clearCookie(){
    if (confirm("您确定要关闭本窗口吗?")){
    alert("ok");
    }else{
    return false;
    }
    </script>
    为什么我这么写点击“确定”关闭窗口,点击“取消”也关闭窗口能?
    各位高手帮帮忙,在线等回复,谢谢!
      

  2.   

    function clearCookie()
    {
    if (confirm("您确定要关闭本窗口吗?"))
    {
    window.opener=null;
    window.close();
    }
    }
      

  3.   


    要这样才行的,function onbeforeunload()
    {
      return "你确定要关闭本窗口吗?";
    }
      

  4.   

    function window.onbeforeunload()
    {
      return "你确定要关闭本窗口吗?";
    }
      

  5.   

    <script language=javascript>
    function window.onbeforeunload() {
      if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
        return false;
    }
    </script>
      

  6.   

    MSDN的例子,大家都想复杂了
    <HTML>
    <HEAD>
    <SCRIPT>
    function closeIt()
      {
        event.returnValue = "Any string value here forces a dialog box to \
                            appear before closing the window.";
      }
    </SCRIPT>
    </HEAD>
    <BODY onbeforeunload="closeIt()">
        <a href="http://www.microsoft.com">Click here to navigate to 
            www.microsoft.com</a>
    </BODY>
    </HTML>