[英]I want to log out my application after browser close in every browser?
我通過此window.onbeforeunload=HandleOnClose;
調用此代碼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 瀏覽器發生崩潰,客戶端代碼將永遠不會執行。 某些 Web 瀏覽器會非常快地自行關閉,並且不會等待執行客戶端代碼。
您應該找到替代解決方案,例如如果用戶在一段時間內不活動,則在服務器端注銷。
無法檢測到用戶何時關閉瀏覽器。 如果您使用 java 並使用 cookie 來檢查用戶是否已登錄,則可以執行 cookie.setMaxAge(-1)。
這將確保在瀏覽器關閉時刪除 cookie。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.