How to fire an event on browser closing [duplicate]
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
精彩评论