zoukankan      html  css  js  c++  java
  • 关闭窗口后立即销毁Session

    当用户非法关闭窗口时,将触发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)
    {


       
  • 相关阅读:
    sql小练习
    登录测试点
    游戏签到
    移动端和pc端微信加入群聊
    小说
    微信语言输入
    linux tar压缩解压缩命令详解
    linux使用nginx配置web服务器
    FFmpeg 视频处理入门教程
    Git学习
  • 原文地址:https://www.cnblogs.com/abcdwxc/p/1017941.html
Copyright © 2011-2022 走看看