Hie,
Im doing a webpage whereby if a user is logged in, and try close the browser, system should prompt warning message.
If user agree to exit , session will be terminated.
I can get this work in IE, but not Mozilla, as in, it will just allow user to close browser without any warning and therefore, the session is still alive.
Anyone face the same prob as well?Or any idea i can get this work?
Thanks
onbeforeunload not working in Firefox
Moderator: General Moderators
Re: onbeforeunload not working in Firefox
can you post the relevant code here?
Re: onbeforeunload not working in Firefox
Following works for me:
Code: Select all
window.onbeforeunload = function(){
return "ARE YOU SURE?"
}Re: onbeforeunload not working in Firefox
Previously, whenever user try to close browser in IE, there will be a prompt, but now , after i change the body tag to use only onbeforeunload instead of both onbeforeunload & onload, and session will be able to terminate in both IE & Firefox, but WITHOUT the prompt which is a part of the requirements on the system.
What i have is in the body tag :
And the js part will be smthg like this :
What i have is in the body tag :
Code: Select all
<body onbeforeunload="ToBeClosed();" onload= "<?= $body_onload;?>">
Code: Select all
function ToBeClosed()
{
var LogoutFlag = document.form1.hidLogoutFlag.value;
var hidLogoutFlag1 = document.form1.hidLogoutFlag1.value;
var PageFlag= document.form1.hidPageFlag.value;
var EndOnClose = parseInt(document.form1.hidEndSessionOnClose.value); //Text
if (PageFlag ==1 && EndOnClose != 0 )
{
callLogout(); // send to another file to terminate the session,update in database
closeWindows();
}
}
Code: Select all
function closeWindows()
{
if (window_count)
{
for (i=0; i < window_count; i++)
{
if (false == my_window[i].closed)
{
my_window[i].close();
}
else
{
}
}
}
}