Solved

How can I get a browser window to reopen itself if the user closes it...using the body onunload statement

Posted on 2004-10-07
6
247 Views
Last Modified: 2008-02-01
I have a holding page where the user must work with a child window that is open also.  If the user closes the parent 'holding' window then the process does not work as smoothly.  Not being a javascript person, what statement do I need to use in the 'body onunload=' that will reopen the browser window to the same page if the user closes it?
0
Comment
Question by:murryc
6 Comments
 
LVL 30

Accepted Solution

by:
third earned 125 total points
ID: 12255870
there will be no smooth solution for your problem as onunload fires not only when you press the X button but also when you refresh the page or navigate to other pages.

i suggest you use our previous method but using this code,

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
  var Cleaned = false;

  function cleanUp(){
    var URL = 'finishpage.html';
    if(window.opener == null || window.opener.closed){
        window.open(URL)
      }
      else{
        window.opener.location.href = URL;
      }
      window.close();
  }
</script>
</head>
<body onunload="if(!Cleaned)cleanUp();">
<a href="finishpage.html" onclick="Cleaned=true;cleanUp();">finish</a>
</body>
</html>
0
 
LVL 30

Expert Comment

by:third
ID: 12255873
btw, that's the new code for the child.html
0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 12256018
here in one Line

<body  onLoad="Z=window.open('a1a.html', 'A', 'width=100 height=100')" onunload="(Z.closed)?'':M=window.open('index.htm');">

So it will LOAD a pop up a1a.html when the Page loads, variable Assign to it is Z, so you can open Child Window anywhere you want but assign it to a variable named Z. Then in unload event define the same path as the MAIN parent window.

so if the child is open parent will keep opening.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 49

Expert Comment

by:Roonaan
ID: 12256662
wouldn't body onunload="return false;" not do the trick?
0
 
LVL 9

Expert Comment

by:riyasjef
ID: 12258007
It is better to close the popup window when "parent" unloads...
like this

var popup;
<script>
function closepopup()
{
      if(popup)
       if(!popup.closed)
          popup.close();
}
</script>

<body onunload="closepopup()">

Riyasjef
0
 

Author Comment

by:murryc
ID: 12259332
thirds solution did the trick, I am sure the others would work as well, but it is working okay
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question