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
244 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

746 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

12 Experts available now in Live!

Get 1:1 Help Now