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

Moving to an anchor in the parent window from a child window 1

Status
Not open for further replies.

WebNickson

Programmer
Dec 8, 2003
46
SG
Hi,

I'm trying to move to an anchor in my parent window using a function called in the child window.

I tried the following code but it just returned my child window in the parent window.

parent.window.location.href='#Instruction1';


Please help! My hair is all white alrdy (lol)

rgds,
Nickson
 
Nickson,

This was a fun one... the solution I used was to call a function from the child page that used the following:

Code:
opener.location.hash = "anchorName";

I built two html files as below to demonstrate that it worked - works for me at least :)

Filename = parent.html
Code:
<html>
<head><title>Parent</title>
<script language=&quot;javascript&quot;>
var myWindow=null;
function popUp()
{
	myWindow=window.open('child.html','mypop','');
}
</script>
</head>
<body>
<a href=&quot;javascript:popUp();&quot;>Launch Child</a>
<h2>Parent</h2>
<p>Lorem ipsum dolor</p>
<p>sit amet, consectetuer</p>
<p>adipiscing elit.</p>
<p>Donec vitae magna.</p>
<p>Aenean vitae augue</p>
<a name=&quot;wibble&quot;></a>
<h2>wibble</h2>
<p>Pellentesque faucibus sapien</p>
</body>
</html>

Filename = child.html
Code:
<html>
<head><title>Child</title>
<script language=&quot;javascript&quot;>
function jumpTo(_myAnchor)
{
	opener.location.hash=_myAnchor;
}
</script>
</head>
<body>
<a href=&quot;javascript:jumpTo('wibble');&quot;>Jump to the wibble anchor</a>
<h2>Child</h2>
<p>Lorem ipsum dolor</p>
<p>sit amet, consectetuer</p>
<p>adipiscing elit.</p>
<p>Donec vitae magna.</p>
<p>Aenean vitae augue</p>
</body>
</html>

I hope this manages to restore some of that hair that was going white (probably too late for most of us).

Jeff
 
Jeff,

You are good! It works with just a simple change of opener to parent since I am using iFrames.

Ah... Now I know how to use the hash command! And I hair is now all glistening black! : )

Thx!

Nickson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top