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
248 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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. …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

830 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