开发者

Detect the browser closing event of Alt+F4 in asp.net

开发者 https://www.devze.com 2023-03-15 05:45 出处:网络
How to detect the browser closing event in asp.net before page unload. I need to call the javascriptfunctionto clear the cookie expire time.

How to detect the browser closing event in asp.net before page unload. I need to call the javascript function to clear the cookie expire time. In body onunload method I'm able to call the function but its calling even if I refresh the page. So, Could anyone can help me out. 开发者_JAVA百科Thanks.


There is no sure shot method of identifying the alt+f4 method of browser as it is happening client side and onunload will be called every time the page will be refreshed, even if you click a link or do a refresh. Instead, you can use a timeout function in javascript, that will call a server side page every 2-5 minutes and you can check the state in your server side code. If the page is not called within the defined time frame, it means that the user has closed the session and you can call Session.Abandon() there.

0

精彩评论

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

关注公众号