100分求助网页是由框架构成,怎么样能实现屏蔽掉ALT+F4和IE的关闭按钮?

chinabs 2003-10-15 06:48:05
我测试过在单个网页里可以实现,代码如下:
function window.onbeforeunload()
{
//禁止关闭窗口
if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
{
alert("无法关闭");
window.event.returnValue="确定要退出本页吗?";
new ActiveXObject("WScript.Shell").sendKeys("{ESC}")
}
}

function document.onkeydown()
{
//捕获ALT+F4键
if(event.altKey&&event.keyCode==9)
{
alert('禁止退出!');
event.keyCode=0;
event.returnValue=false;
}
}
但是在框架里怎么实现呢?
...全文
32 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qnzu 2003-10-15
  • 打赏
  • 举报
回复
能否不询问,直接没有任何提示的屏蔽掉?
zhfkiller 2003-10-15
  • 打赏
  • 举报
回复
下面的代码放在主框架页中,可以询问是否要关闭
<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>
zhfkiller 2003-10-15
  • 打赏
  • 举报
回复
将下面代码放在组框架页上,仍能禁止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不存在
zhfkiller 2003-10-15
  • 打赏
  • 举报
回复
在单个页面里也只需
function window.onbeforeunload()
{
//禁止关闭窗口
if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
{
alert("无法关闭");
window.event.returnValue="确定要退出本页吗?";
new ActiveXObject("WScript.Shell").sendKeys("{ESC}")
}
}

不需要后面部分
suhuoqiang 2003-10-15
  • 打赏
  • 举报
回复
那是不可能地

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧