Posted on 2007-03-21 13:29
玄铁剑 阅读(301)
评论(0) 编辑 收藏 引用 所属分类:
ASP.NET相关
關閉窗體關閉事件
方式一:
<script language="javascript">
function window.onbeforeunload()
{
if(event.clientX>document.body.clientWidth&&event.clientY<0 ||event.altKey)
{
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET","exit.aspx",false);
xmlhttp.send();
}
}
</script>
然后在exit.aspx里
Session.Clear();
<iframe name=body frameBorder=0
改为
<iframe name=body1 frameBorder=0
方式二:
在页面body onbeforeunload 事件里提交服务器,设置session立即过期。
...
<script language=javascript>
function Quit()
{
document.all.clientCommand = "Quit";
document.forms[0].submit();
}
</script>
<body onbeforeunload="Quit()">
...
<input type="hidden" id="clientCommand" runat="server">
...
</body>
codebehide
===========
Page_Load事件处理方法中:
if(this.clientCommand.Value == "Quit")
this.Session.TimeOut = -1;
枚舉窗體然後關閉
1)得到窗体的数量
2)得到打开窗体的句柄
1)好解决,因为你的窗体都是有一个父窗口打开的,所以在这个父窗口中使用cookie记录下带开窗口的最大数就行了。这样就能再另一个地方通过cookie和循环得到打开窗口的名称。
2)也不难,因为我们知道打开窗口的名称了。我们使用window.open()函数得到打开窗口的句柄。
所以这样解决:
var wmax=cookie中窗口的最大数量;
var wopened;
for(i=0;i<wmax;i++){
wopened=window.open("","abcwindow_" + i,"top=2000,width=1500");
wopened.close();
}
完成。
關閉窗體清除Cache
<body onbeforeunload="window.open('clear.aspx','','top=4000')">