在单个页面里也只需
function  window.onbeforeunload()
{
//禁止关闭窗口
if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
{
alert("无法关闭");
window.event.returnValue="确定要退出本页吗?";
new ActiveXObject("WScript.Shell").sendKeys("{ESC}")
}
}不需要后面部分

解决方案 »

  1.   

    将下面代码放在组框架页上,仍能禁止Alt + F4关闭窗口:
    <html>
    <head>
    <script>
    function  window.onbeforeunload()
    {
    //禁止关闭窗口
    if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
    {
    alert("无法关闭");
    window.event.returnValue="确定要退出本页吗?";
    }
    }
    </script>
    </head>
    <frameset rows="64,*">
      <frame name="header" scrolling="no" noresize target="main" src="f1.htm">
      <frame name="main" src="f2.htm">
      <noframes>
      <body>
      <p>此网页使用了框架,但您的浏览器不支持框架。</p>
      </body>
      </noframes>
    </frameset>
    </html>
    之所以不能禁止关闭按钮关闭窗口,是因为组框架页面没有body,即document.body.clientWidth不存在
      

  2.   

    下面的代码放在主框架页中,可以询问是否要关闭
    <html>
    <head>
    <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 2</title>
    <script>
    function  window.onbeforeunload()
    {
    window.event.returnValue="";
    }
    </script>
    </head>
    <frameset rows="64,*">
      <frame name="header" scrolling="no" noresize target="main" src="f1.htm">
      <frame name="main" src="f2.htm">
      <noframes>
      <body>
      <p>此网页使用了框架,但您的浏览器不支持框架。</p>
      </body>
      </noframes>
    </frameset>
    </html>