Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting back to original page after pop-up window closes.

Status
Not open for further replies.

gns100

Programmer
Aug 11, 2003
40
US
Here's some simple code that illustrates my problem.
On the first page I just "Click here" to go to the pop-up window.

Code:
<html>
<head>
<title>Initial Page</title>
</head>
<body>

<p><a href="test-initial.html">Click Here</a></p>

</body>
</html>

Pop-up window code

Code:
<html>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">

function xpopUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=450,left = 100,top = 50');");
}

getURL = "test.html";
xpopUp(getURL);
</script>
<title>test</title>
</head>
<body>
</body>
</html>

Pop-up window code. At the bottom of the window the user clicks the "Close Window" button and the window closes (see function test_popup().

Code:
<html>
<head>
<title>Pop-Up Window</title>
<style fprolloverstyle>A:hover {color: #FF0000}
</style>
<script language="javaScript">

function test_popup(){
window.close();
}

</script>
</head>

<body bgcolor="#FFCC00">

<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="579" height="261" bgcolor="#D0DDA8">
  <tr>
    <td width="174" height="101">
    <p align="center">
    &nbsp;</td>
    <td width="402" height="101">
    <p align="center"><b><font face="Arial" size="4" color="#FF0000">Test Pop Up 
    Page<br>
&nbsp;</font></b></td>
  </tr>
  <tr>
    <td width="174" height="203" bgcolor="#FFFFCC">
    <p class="MsoBodyText" style="margin-left: 9; margin-right: 9" align="center">
    &nbsp;</td>
    <td width="402" height="203" bgcolor="#FFFFCC">
    <p style="margin-left: 15; margin-right: 15" align="justify">
    &nbsp;</td>
  </tr>
</table>
<br>
<center><BUTTON onClick=test_popup()>Close Window</BUTTON></center>
<br>
</body>
</html>

The problem is that after the window closes, I would like to be back on the page where I called the pop-up window. Instead a blank page is open corresponding to the second page and the initial page has disappeared.

Is there a way to get back to the starting point and eliminate the blank page?

Thanks for any help you can offer.

 
you could change

function test_popup(){
window.close();
}

to

function test_popup(){
opener.history.go(-1);
window.close();
}

or

function test_popup(){
opener.location.href = "originalPage.html";
window.close();
}


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Why do you have to have an intermediate page to launch your popup?

You can add the function "xpopUp()" on the initial page and change your link to the following:
Code:
<p><a href="#" onclick="xpopUp('test.html');return false;">Click Here</a></p>

make sure that you remove the line with xpopUp(getURL); because that is the command that is launching the popup on your second page. You don't need that now.

This way the window.close(); is all that is needed.


Einstein47
(&quot;The pure and simple truth is rarely pure and never simple.&quot; - Oscar Wilde)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top