Link to home
Start Free TrialLog in
Avatar of gtsupport
gtsupport

asked on

onunload doesn't work in Firefox

Hi,

I have the following codes:

<script type="text/javascript">

            var myclose = false;

            function ConfirmClose(event)
            {
                        event = event ? event : window.event;
                        event.returnValue = 'Any message you want';
                        setTimeout('myclose=false',100);
                        myclose=true;
            }

            function HandleOnClose()
            {
                  if (myclose==true) alert("Window is closed");
            }

and on the page:

<body bgcolor="#FFFFFF" onbeforeunload="ConfirmClose(event)" onunload="HandleOnClose()">

The problem is that, after clicking X to close the browser, IE6 closes and alerts, the onunload fires but not in firefox.

In addition, I want to modify the codes to do this:

1. If the user clicks OK - the window willnot close, instead goto another PHP page.
2. If the user clicks Cancel, stays on the current page.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gtsupport
gtsupport

ASKER

Thanks,

But now I have another problem,

I want to do processing on a specific page and I want to call that page when  the user Clicks on OK to confirm the closing event,

so, I am thinking if I can put the codes below, see comments:

function HandleOnClose(myclose1)
            {
                            if (myclose1==true)
                                    //change alert to redirect to page.
                            alert("Window is closed");
            }
It will be a great help if this is possible. since I have tried using window.location = http://example.php

but it doesn't work.
People are trying to leave your page for another page and you want to intercept that they are leaving and redirect them to another page

So I want to lave your page for my bank. You intercept the call and redirect to a page that looks like my bank???

Not very good security... So it is not allowed