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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onClick="window.close()" - PROBLEM

Status
Not open for further replies.

LucyL

Technical User
Feb 20, 2002
113
0
0
US
Hi,
I have a pop-up box that displays some information. I want to close this pop-up and return to my original window using window.close(), but I want to return to a specific section on the original page using an anchor. Is it possible to do this?
Thank you.
 
Sure... assuming the original page was the opener, you can target the opener and set the location to '#anchorname'.

Jeff
 
Hi Jeff, this is what I was using but with no luck. Here is what I have below. I'm not sure what I'm doing wrong?

On the opening page:
-the anchor:
<a name="model"></a>

-the link:
<a href="#" onClick="window.open('defs.htm','layout','toolbar=no,menubar=no,scrollbars=yes')" style="text-decoration:underline; font-weight:normal; color:#333399">Open new window</a>

On the pop-up window then...
<a href="#model" style="text-decoration:underline; font-weight:normal; color:#333399" onClick="window.close()">Close Window</a>


...any ideas?
 
Leave the anchor as you had it... although some browsers might require there to be some content between the tags (a non breaking space works if you see this happening).

Next make a minor change to your link on the initial page (this prevents the actual page from trying to load the # url). Basically I have added a return false in the javascript section (to prevent the link from opening normally) and added the real link to defs.htm (in case they don't have javascript enabled this will at least let them open the link):

Code:
<a href="defs.htm" onClick="window.open('defs.htm','layout','toolbar=no,menubar=no,scrollbars=yes'); return false;" style="text-decoration:underline; font-weight:normal; color:#333399">Open new window</a>

There is a final change to the close window link on the defs.htm file. This is some javascript that is run before the popup window is closed. I added a (mock) link to the href so that non javascript users will still be able to use your solution (up to you of course if you choose to support these users):

Code:
<a href="mypage.html#model" onClick="opener.location=opener.location+'#model';window.close();">Close Window</a>

Hope you can cobble something from all that!

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top