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
LVL 1
gtsupportAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pratima PharandeCommented:
Try like this

<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(myclose1)
            {
                            if (myclose1==true) alert("Window is closed");
            }
            </script>

 

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gtsupportAuthor Commented:
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.
0
Michel PlungjanIT ExpertCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.