<script for=window event=onbeforeunload>
if (event.clientX>document.body.clientWidth &&event.clientY<0||event.altKey)
return ""
</script>

解决方案 »

  1.   

    就是判断鼠标点击的的位置是否关闭按钮,或者截获alt+F4
      

  2.   

    最终这个问题没有很圆满的解决,不能不说有点遗憾,在MSDN上有这样一段话,所以我也就不抱希望能完美解决这个问题了。
    Q:When a user attempts to close a browser window by clicking the X icon on the title bar, I would like to be able to capture the event. In the past, the "return false" and "event.returnValue = false" statements could not be used to cancel an onbeforeunload so a malicious site could not prevent you from navigating away. Has this changed with the latest versions of JScript&reg;?
    event::closeBrowser () {
     if(!confirm("are you sure you want to close this window?")) {
        //do not close window
        return false;
     }    
    }A :
     The MSDN&reg; Library includes a page that explains the use of the onbeforeunload event and does exactly what you want (onbeforeunload Event). If you want to distinguish between browsing to a new page and closing the browser, Internet Explorer 5.5 and higher offer the WindowClosing event, defined on the DWebBrowserEvents2 interface. The bad news is that you can't capture this event with JScript; the only way is with a language like C++ or Visual Basic&reg;.
    You could also set a flag in the onclick event of any anchor and check it in the onbeforeunload handler:<SCRIPT>
    var nav=false;
    function closeIt()
    {
       if (nav==false)
        event.returnValue = "Any string value here will force a dialog 
                            box to appear before closing the window.";
    }
    </SCRIPT>
    &#8226;&#8226;&#8226;
    <a href="http://www.microsoft.com" onclick="nav=true;">
     Click here to navigate to www.microsoft.com</a>This isn't foolproof. For example, if the user right-clicks on the anchor tag and selects Open, this won't work. This method also doesn't handle the case where the user types a URL into the Address bar, selects a link from Favorites or the Links bar with Reuse Browser Window selected in Advanced Options, loads a URL from a Microsoft Outlook&reg; message or Word doc, and so forth.
    Remember that invoking onbeforeunload prevents you from leaving the page without getting a prompt, owing to the security reasons you mentioned.
    其连接是:http://msdn.microsoft.com/msdnmag/issues/02/07/WebQA/default.aspx