开发者

How to fire an event on browser closing [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

javascript detect browser close tab/close browser

Hello guys,

I have problem to detect the session end when the browser is closed, how can i get this, i want to fire a query to store the login time information in da开发者_运维技巧tabase, please help me. Thanks to all


It is highly unreliable to rely on that, An ajax query may not be completed on browser close.

Solution:

Sending a heartbeat request every x seconds in order to tell if the user left or not.


You could create a hidden button and then fire the button click event using

function doUnload()
{
 if (window.event.clientX < 0 && window.event.clientY < 0)
 {
   document.getElementByID('HiddenButton').click() }
}
<body onunload="doUnload()">

Never tried it but it might work :)

or you could use the global.aspx methods

    protected void Session_End(object sender, EventArgs e)
    {

do something; }

    protected void Application_End(object sender, EventArgs e)
    {

do something; }

Sp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜