Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 22nd, 2003, 01:00 AM
Registered User
 
Join Date: Jul 2003
Location: Lahore, Punjab, Pakistan.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Close Parent window on opening child window

AOA All,
I m thank ful to all ppl at forum coz when ever i faced any problem .. i got solution from this forum ...
i have to web pages suppose a1.html and a2.html .. and i want that when i click on the link of a2.html from a1.html .... the second page a2.html will open in a new window ... and the parent window (a1.html) will close ..
i ll appriciate ur quick response and sample code ..
  #2 (permalink)  
Old September 22nd, 2003, 02:57 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Do you mean like this:

a1.html
-------
Code:
<html>
<head>
<title></title>
</head>
<body>

<a href="a2.html" target="_blank">open a2.html</a>
</body>
</html>
a2.html
-------
Code:
<html>
<head>
<title></title>
</head>
<!-- this javascript closes a1.html, 
but you will be prompted to confirm the closure -->
<body onload="window.opener.close();">
This is a2.html
</body>
</html>
  #3 (permalink)  
Old September 24th, 2003, 02:09 AM
Registered User
 
Join Date: Jul 2003
Location: Lahore, Punjab, Pakistan.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much dear for your response.
i already have checked this method but actually i want all this with out conformation box ... is it possible with out confirmation message(prompt).
Thanks again for your help ...
  #4 (permalink)  
Old September 24th, 2003, 03:02 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You could close the child window (a2.html) without prompt, but not the main window.
  #5 (permalink)  
Old September 24th, 2003, 11:00 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rather than having the child window close the parent, could the parent close itself when the child is launched?

Use this in a1.html:

<a href="a2.html" onclick="window.opener=self;window.close();">
  #6 (permalink)  
Old April 9th, 2004, 12:53 PM
Registered User
 
Join Date: Apr 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Would there be a way to do this without clicking anything?

  #7 (permalink)  
Old April 9th, 2004, 01:11 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

<body onload="window.opener=top;window.open('yourpage.ht ml');window.close()">

HTH,

Snib

P2P Member
<><
  #8 (permalink)  
Old April 9th, 2004, 04:08 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Or if you didn't want a new window to open, you could take out the window.open() part.

Snib

P2P Member
<><
  #9 (permalink)  
Old April 11th, 2004, 12:06 PM
Registered User
 
Join Date: Apr 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

is there a way to do it keeping onLoad out of the body tag?

Code:
<!--


    window.onload = function() {

    x=(screen.availWidth-760)/2;
    y=(screen.availHeight-500)/2;
    var choose=window.open('newWin1.html','gp','scrollbars=yes,resizable=no,width=760,height=500,status=no,location=no,toolbar=no, menubar=no,top='+x+',left='+y+',screenY=0,screenX=0');

}
-->


Similar Threads
Thread Thread Starter Forum Replies Last Post
Close Child window automatically on closing parent vikas67k C# 1 August 26th, 2008 02:00 AM
Closing parent window from child window arnabghosh Javascript How-To 1 December 26th, 2007 01:18 AM
Submitting a parent form from a child window in IE livehed Other Programming Languages 0 February 15th, 2007 01:07 PM
closed parent window when opened child window jaiwin Javascript How-To 0 October 8th, 2006 12:54 PM
Propogating changes in child window to parent Scripts82 ASP.NET 1.0 and 1.1 Basics 4 September 22nd, 2006 07:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.