Forum Moderators: open

Message Too Old, No Replies

Opening "Target" window; closing open window

         

joshenry

11:08 pm on May 26, 2005 (gmt 0)

10+ Year Member



Hi,

When opening a new "target" window, it opens a new window while leaving the old window still open. I want to close the window.

the scenario: MainPage has a link that opens a new window named "New1". Window New1 has a link that opens a new window named "New 2". Now I want a link on page New 2 to open a new page in window "New1" (which is already open) while at the same time closing itself (window "New2").

Is there any way to do that [in the "HREF" tag]?

Joseph

tedster

11:32 pm on May 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can reference the window new1 from a link in the window new2 with window.opener

<a href="#" onClick="window.opener.parent.location='newpage.html';window.close();">

joshenry

12:27 am on May 27, 2005 (gmt 0)

10+ Year Member



Sorry, but I'm not understanding exactly what you mean.

The "#" represents the new url. Do I need "Target=New1" so it will replace the contents in window New1 which is already open?

Also is 'newpage.html' the actual syntax or should I substitude the url of the page that's open in window New2 ...the one I want to close?

What am I reading incorrectly?

I've tried all the possible combinations and can't get it right. :(

tedster

1:36 am on May 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I intended newpage.html to stand for the actual url that loads in win1. No, you don't use a target attribute in this case - the javascript "aims" the url at the appropriate window by changing the location of "window.opener"

You can put the url in place of the # - that's in addition to, and not in place of, the javascript. This would give you spiderable pages, and some functionality for people whol don't have javascript for whatever reason.

<a href="newpage.html" onclick="window.opener.parent.location='newpage.html';window.close();return false;">

Essentially, the javascript says "When this link is clicked --

1) load newpage.html in the window that opened this one;
2) close this window;
3) ignore the regular href attribute in the html anchor tag;"

There may well be other javascript approaches - I only know a little bit and I'm sure the folks in our Javascript Forum [webmasterworld.com] would be glad to help further.

joshenry

5:30 pm on May 27, 2005 (gmt 0)

10+ Year Member



Thanks for the reply,

Your explanation confirmed that I did understand what you were saying. It just doesn't do what it's supposed to?

I'm gonna try the javascript forum like you suggested. Thanks.

sgina

6:43 pm on May 27, 2005 (gmt 0)

10+ Year Member



"the scenario: MainPage has a link that opens a new window
named "New1". Window New1 has a link that opens a new
window named "New 2". Now I want a link on page New 2 to
open a new page in window "New1" (which is already open)
while at the same time closing itself (window "New2")."

From my understanding, you can just <a href="javascript:window.close();">Link</a> on page New 2. It will close itself, leaving you window New1 that's already opened.

joshenry

7:17 pm on May 27, 2005 (gmt 0)

10+ Year Member



he-he ...if it were only that simple.

Here's the deal. Window new2 might be opened from window new1 "OR" it may be open from another source. If window new1 were not the source, it's necessary for it to open window new1 ....so you can see just closing the window is not the answer.

I did post the question to the javascript forum as you suggested.