onbeforeunload not working in Firefox

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
angelena
Forum Commoner
Posts: 53
Joined: Mon Nov 22, 2004 4:10 am

onbeforeunload not working in Firefox

Post 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
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: onbeforeunload not working in Firefox

Post by Eran »

can you post the relevant code here?
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Re: onbeforeunload not working in Firefox

Post by kaszu »

Following works for me:

Code: Select all

window.onbeforeunload = function(){
    return "ARE YOU SURE?"
}
angelena
Forum Commoner
Posts: 53
Joined: Mon Nov 22, 2004 4:10 am

Re: onbeforeunload not working in Firefox

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