?
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
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 30

Accepted Solution

by:
third earned 500 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

718 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