Gossamer Forum
Home : General : Internet Technologies :

javascript: open in parent window/new window

Quote Reply
javascript: open in parent window/new window
I am trying to do the following:

1. parent window opens child window.
2. there is a link in the child window, that should open in the parent window

This all works fine, using the following code in the parent window:
Code:
<script language=JavaScript>
<!--
function checkWindow(window) {
msgWindow=open('',window,'resizable=yes,width=200,height=100');
if (msgWindow.opener == null) msgWindow.opener = self;
};
//-->
</script>

<a href="check.cgi" alt="Check" target="check" onClick="checkWindow('check');" >Monitor</a>
and the following code in the child window
Code:
<script language="JavaScript"><!--
function load(file,target) {
target.window.location.href = file;
}
//--></script>

<a href="#" onClick="load('script.cgi',top.opener)">Details</a>

The problem I having is that when the user has closed the parent window, nothing happens when they click on the 'Details' link in the child window. I would like to check if the parent window is still open, and if not, open a new window, and then display the page in that new window.

How would I do that?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] javascript: open in parent window/new window In reply to
It may be easier to add an onunload event to the parent window that warns the user not to close the parent?
Quote Reply
Re: [Paul] javascript: open in parent window/new window In reply to
Or close the child window when closing the parent window....

Are you saying what I want is not possible?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] javascript: open in parent window/new window In reply to
No, I just don't know how to do it Blush
Quote Reply
Re: [yogi] javascript: open in parent window/new window In reply to
Hello Yogi,

Code:
Parent :<HTML>
<HEAD>
<script language="Javascript">
function openWindow(theName) {
// BOB is the NAME of the window we are opening.
msgWindow=open(theName,'BOB','resizable=yes,width=300,height=200');
return false;
}
</script>
</HEAD>
<BODY>
<a href="Javascript:void(0);" alt="Check" onClick="openWindow('http://127.0.0.1/child.html');" >Monitor</a>
</BODY>
</HTML>
Child :<HTML>
<HEAD>
<TITLE>Child Window </TITLE>
<script language="javascript">
function changeParentHREF(myURL) {
if(!window.opener.closed && window.opener != null){
//window is open
window.opener.location.href=myURL;
}
else{
// window is not open }
newWindow=open(myURL,'harry','');
}
}
</script>
</HEAD>
<BODY>
<a href="Javascript:void(0);" alt="Check" onClick="changeParentHREF('http://127.0.0.1/mary.html');" >Change Parent Href ?</a>
</BODY>
</HTML>


The parent opens the child and then the child changes the parent or opens a new window

with the URL desired as in the mary.html above.

Hope this makes sence.

Cornball
Quote Reply
Re: [cornball] javascript: open in parent window/new window In reply to
Thanks for the example. I tried it, and it works in Netscape and IE, but it doesn't work in Konqueror, or Galeon....

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] javascript: open in parent window/new window In reply to
Hello Yogi,

You can test if Konquerer and use in the child:

<a href="http://127.0.0.1/mary.html" alt="Check" target="SPECIALZ">Static Change Parent Href ?</a>

as long as the parent has in the script:

window.name="SPECIALZ";

This will open a new window in IE if the parent has closed, I do not have access to Konquerer to test.

Sorry I have not played with Galeon.

cornball
Quote Reply
Re: [cornball] javascript: open in parent window/new window In reply to
Thanks for the suggestion. Unfortunately, it didn't work, neither in Konqueror nor in Galeon...

Ivan
-----
Iyengar Yoga Resources / GT Plugins