[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1589
  • Last Modified:

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
0
gtsupport
Asked:
gtsupport
1 Solution
 
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
 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now