Terry's blog

Focus on bigdata and cloud.

博客园 首页 新随笔 联系 订阅 管理
当用户非法关闭窗口时,将触发nunload事件,所以可以在此定位到另一个页面,进行session的销毁。
代码如下:

 1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
 2
 3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 4
 5<html xmlns="http://www.w3.org/1999/xhtml" >
 6<head runat="server">
 7    <title>无标题页</title>
 8<script  language="javascript">
 9
10function ClosePage()
11{
12if((window.screenLeft>=10000 && window.screenTop>=10000)||event.altKey)
13 {
14   window.location.href="/ClosePage.aspx" 
15  }

16}

17
18</script>
19</head>
20<body  onunload="ClosePage()">
21    <form id="form1" runat="server">
22    <div>
23        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
24    </form>
25</body>
26</html>
在ClosePage.cs页面的  Page_Load销毁如下:     Session.Abandon();    
注意:当刷新页面的时候也会触发onunload事件,所以需要判断是否进行关闭再执行Session的销毁操作。即:
if((window.screenLeft>=10000 && window.screenTop>=10000)||event.altKey)
{


   
posted on 2007-12-28 09:43  王晓成  阅读(2898)  评论(0编辑  收藏  举报