我通过 window.onbeforeunload=HandleOnClose;
调用此代码
这在 IE 中工作正常,但在其他浏览器中却不行。此代码特定于 IE,但不适用于其他浏览器。我们如何在所有浏览器中检测浏览器的关闭事件?
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
}
}
}
}
最佳答案
我认为不可能总是让用户注销。如果用户的网络浏览器崩溃,客户端代码将永远不会执行。某些 Web 浏览器会非常快速地自行关闭,不会等待执行客户端代码。
您应该找到替代解决方案,例如如果用户在特定时间段内不活动,则在服务器端注销。
关于java - 我想在每个浏览器关闭浏览器后注销我的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12581250/