我想检测用户何时关闭浏览器窗口?

I want to detect when user close browser window?(我想检测用户何时关闭浏览器窗口?)
本文介绍了我想检测用户何时关闭浏览器窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有示例,我需要在用户关闭浏览器窗口时终止会话.我试过 page_unload() 不工作.示例是:我有父窗口,窗口将从它打开我需要在用户关闭子窗口时删除会话.请我需要一些帮助.

I have Example and i need to kill the session when user close his browser window. i tried page_unload() not working. the example is:i have parent windows and window will open from it i need to delete session when user close the child window. please i need some help.

推荐答案

您可以使用回发到注销页面的 window.onbeforeunload 处理程序来执行此操作.

You can do this with an window.onbeforeunload handler that posts back to a sign out page.

function CloseSession( )
{
    location.href = 'SignOut.aspx'; 
}
window.onbeforeunload = CloseSession;

这是重复问题.. chk out here

This is the duplication question.. chk out here

关闭浏览器实际上应该清除会话变量一个 ASP.net 会话 id

https://stackoverflow.com/questions/920042/kill-server-side-session-on-browser-window-close-closed

这篇关于我想检测用户何时关闭浏览器窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)