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
245 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:adilkhan
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now