关闭浏览器实际上应该清除会话变量 [英] Closing the browser should actually clear the session variables

查看:92
本文介绍了关闭浏览器实际上应该清除会话变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,
我正在创建一个包含聊天模块的应用程序.从数据库中获取了可用的用户.表格表OnlineUsers中有一个列
值存储在位中.
现在,如果用户在线,它将存储1.每当用户注销时,便对该表进行更新并将其值设置为0.

当用户直接关闭浏览器时,我想调用一个方法,该方法用值0更新表,以便他在聊天窗口中不可用.

Hello Friends,
I am creating an application in which there is a chat module.Available users are fetched from the database.There is a column in the table table OnlineUsers
in which value is stored in bit.
Now if a user is online it stores 1.Whenever a user logsout an update is made to the table and value is set to 0.

When a user directly closes the browser i want to call a method that updates the table with value 0 so that he is not available in the chat window.

推荐答案

不能保证-始终可以在没有任何通知的情况下断开浏览器与会话的连接.例如,通过关闭PC电源,重置ADSL调制解调器等.您可以使用Javascript UnLoad事件,但我认为它在所有浏览器中的工作原理都不相同. http://www.w3schools.com/jsref/event_onunload.asp [
You can''t guarantee it - it is always possible to disconnect a browser from you session without any notification. For example, by turning the PC power off, resetting the ADSL modem, etc.. You can use the Javascript UnLoad event, but I don''t think it works the same in all browsers. http://www.w3schools.com/jsref/event_onunload.asp[^]


请参考类似的主题:
在浏览器上清除会话变量close [在服务器端处理浏览器关闭事件 [ ^ ]
关闭浏览器实际上应该清除会话变量 [
Please refer similar threads:
Clearing Session Variables on browser close[^]
Handle Browser Close Event on the Server-Side[^]
Closing the browser should actually clear the session variables[^]


使用此代码将解决您的问题

use this code it will solve ur problem

<script type="text/javascript">
function unload()
    {

               var btn =document.getElementById('BtnSave');

                 //alert(btn);
                 btn.click();
//        if (Flg==false)
//        {
//            event.returnValue = "UNSAVED DATA WILL BE LOST!!";
//        }
    }
</script>

<body onbeforeunload="unload()">


这篇关于关闭浏览器实际上应该清除会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆