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

Pass a anchor back to the opening window

window.opener

Pass a anchor back to the opening window

by  GUJUm0deL  Posted    (Edited  )
Hi, this problem arose for a friend of mine, and thought if he had a problem, so might someone else. This breif tutorial will explain how to pass a anchor tag back to the opening window.

Code:
[color red]
[b]PAGE1.HTML[/b]
<html>
<head>
</head>

<body>
<a href="page2.html" target="_blank">click me</a>
<p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasd
a</p><p>adasda</p><p>adasda</p><p>adasda</p>
<p><a name="#somethingelse"></a>anchor 1</p>
<p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasd
a</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>
adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</
p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>ada
sda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><
p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda
</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>a
dasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p
><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adas
da</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p>
<p><a name="#somethingelse2"></a>anchor 2</p>
<p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasd
a</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>
adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</
p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>ada
sda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><
p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda
</p><p>adasda</p><p>adasda</p><p>adasda</p><p>adasda</p><p>a
dasda</p>
</body>
</html>
[/color]

[color green]
[b]PAGE2.HTML[/b]
<html>
<head>

<script>
function Gm(url){
//this function names the 'window.opener.location' the url attribute of the function Gm
window.opener.location=url
}
</script>
</head>

<body bgcolor="#FFFFFF">
<form>
<!--- you will have to place the page in a <form> tags like I did above to make this work.  

Now use the onClick event handler to call the function that points to the parent window and the anchor tag in question.  At the same time, once the user clicks the link, the 'window.close()' feature will close the child window.  If you don't want to close the child window but want to put focus on the parent window do 'window.opener.focus()' (see second link for example) --->
<a href="javascript:void(0)" onClick="Gm('page1.html#somethingelse'); window.close();">click, and window will close afterwards</a>
<br>
<br>
<br>
<a href="javascript:void(0)" onClick="Gm('page1.html#somethingelse2'); window.opener.focus();">click, and focus is shifted to the main window</a>
</form>
</body>
</html>
[/color]

Any questions?? Feel to email me.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top