Forum Moderators: open

Message Too Old, No Replies

Parent and Child window navigation

How to do this?

         

Champak

5:31 pm on Feb 26, 2007 (gmt 0)

10+ Year Member



I have a parent/main window that will open up a child window to do a search function. When the search is performed links pop up to open up the desired pages. These desired pages is a part of the main site. I would prefer that instead of the links being opened in the child or another window, clicking the link would close the child window, and open up the page in the original parent window. Is this possible? Can I get some help on this?

Thanks.

jatar_k

5:36 pm on Feb 26, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I believe you could do this with javascript, though I am not positive on the syntax. I moved your thread to the js forum for the experts.

Birdman

5:43 pm on Feb 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you can access the parent with "window.opener". Put this in the head of the popup:

<script type="text/javascript">
function openParent (url) {
if (window.opener &&!window.opener.closed){
window.opener.location = url;
window.close();
}
}
</script>

Then your links:
<a href="/search_result.html" onclick="openParent(this.href)">

Added: that was quick jatar_k!

[edited by: Birdman at 5:44 pm (utc) on Feb. 26, 2007]

Champak

9:27 pm on Feb 26, 2007 (gmt 0)

10+ Year Member



Thank you works perfectly.

I have another link that I was trying to incorporate what you have into it, but on IE an alert box pops up asking if I want to close the window, and on FF nothing happens. What's wrong.

Here's what I have:
<? $tester = "http://google.com";?>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function popNewWindow() {
window.open("<?echo $tester;?>", "popup",
"width=800,height=600,scrollbars=no,menubar=no"
);
window.close();
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<A href onclick="javascript:popNewWindow();">Open new window!"</A>
</BODY>
</HTML>

Also I would prefer the url to be in the href code instead of in the javascript like yours; but I can't get it like that. And a simple way to maximize the window instead of putting width and length.