Page 1 of 1

onbeforeunload not working in Firefox

Posted: Thu Jun 26, 2008 8:59 pm
by angelena
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

Re: onbeforeunload not working in Firefox

Posted: Fri Jun 27, 2008 7:58 am
by Eran
can you post the relevant code here?

Re: onbeforeunload not working in Firefox

Posted: Fri Jun 27, 2008 11:19 am
by kaszu
Following works for me:

Code: Select all

window.onbeforeunload = function(){
    return "ARE YOU SURE?"
}

Re: onbeforeunload not working in Firefox

Posted: Sun Jun 29, 2008 9:52 pm
by angelena
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 :

Code: Select all

<body onbeforeunload="ToBeClosed();"  onload= "<?= $body_onload;?>"> 
 
And the js part will be smthg like this :

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
            {
                
            }
        }
    }
}