[英]I want to log out my application after browser close in every browser?
I am calling this code by this window.onbeforeunload=HandleOnClose;
我通过此
window.onbeforeunload=HandleOnClose;
调用此代码window.onbeforeunload=HandleOnClose;
This is working fine in IE but not in other browsers.这在 IE 中工作正常,但在其他浏览器中无效。 This code is specific for IE but this is not working in other browsers.
此代码特定于 IE,但这不适用于其他浏览器。 How can we detect close event of browser in all the browser ?
我们如何在所有浏览器中检测浏览器的关闭事件?
function ConfirmClose()
{
if (isIE7Min) //To check for IE Version 7.0 and above
{
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if ((b && window.event.clientY < 0) || window.event.altKey)
{
if (!self.closed)
{
refresh = true;
}
}
}
else //IE Version 6.0 and below
{
if (event.clientY < 0 && event.clientX < 0)
{
if (!self.closed)
{
refresh = true;
}
}
}
}
/*Function for onunload*/
function HandleOnClose()
{
ConfirmClose();
if (isIE7Min)
{
if ((window.event.clientX > 0 && window.event.clientY < 0) || window.event.altKey)
{
if (refresh == true)
{
window.open("/DealPricingJavaUAT/DealPricingJsp/Home/logout.jsf");
//Code That redirects to the Session Invalidation Page
}
}
}
else
{
if (event.clientY < 0 && event.clientX < 0 || window.event.altKey)
{
if (refresh == false)
{
window.open("/DealPricingJavaUAT/DealPricingJsp/Home/logout.jsf");
// Code That redirects to the Session Invalidation Page
}
}
}
}
I don't think it is possible to always log user out.我认为不可能总是注销用户。 If there is a crash on user's web browser, the client-side code will never get executed.
如果用户的 Web 浏览器发生崩溃,客户端代码将永远不会执行。 Some web browsers shutdown itself very fast and don't wait to execute the client-side code.
某些 Web 浏览器会非常快地自行关闭,并且不会等待执行客户端代码。
You should find an alternative solution, like logging out on server side if user is not active for certain period of time.您应该找到替代解决方案,例如如果用户在一段时间内不活动,则在服务器端注销。
Its not possible to detect when the user closes the browser.无法检测到用户何时关闭浏览器。 If you are using java and using cookies to check if the user is logged-in, you can do cookie.setMaxAge(-1).
如果您使用 java 并使用 cookie 来检查用户是否已登录,则可以执行 cookie.setMaxAge(-1)。
This will make sure that cookies are deleted when browser closes.这将确保在浏览器关闭时删除 cookie。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.