INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

window.opener

Pass a anchor back to the opening window by GUJUm0deL
Posted: 27 Jul 04

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


PAGE1.HTML
<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>



PAGE2.HTML
<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>

Any questions??  Feel to email me.

Back to Javascript FAQ Index
Back to Javascript Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close