adinas
asked on
Javascript across two windows
What I need to do is as follows:
One window Opens a different window when someone hits a link. I then want the second window to make the first window relaod (refresh) and close itself. I've been able to do everything except get the first window to reload itself. How do I do this?
One window Opens a different window when someone hits a link. I then want the second window to make the first window relaod (refresh) and close itself. I've been able to do everything except get the first window to reload itself. How do I do this?
ASKER
OK. It didn't work for me. I will show what i have on each page:
x.htm
------
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY ONLOAD="alert('hello')">
<FORM action="x1.htm" method=POST id=form2 name="LangCombo" target="xx">
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</FORM>
<P> </P>
</BODY>
</HTML>
x1.htm
-------
<HTML>
<HEAD>
</HEAD>
<body ONLOAD="x()">
<script>
function x() {
if ( self.opener && !self.opener.closed ) self.opener.location=self. opener.loc ation.href ;
window.close();
}
</script>
</body>
</html>
Is there somthing I need to change?
x.htm
------
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY ONLOAD="alert('hello')">
<FORM action="x1.htm" method=POST id=form2 name="LangCombo" target="xx">
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</FORM>
<P> </P>
</BODY>
</HTML>
x1.htm
-------
<HTML>
<HEAD>
</HEAD>
<body ONLOAD="x()">
<script>
function x() {
if ( self.opener && !self.opener.closed ) self.opener.location=self.
window.close();
}
</script>
</body>
</html>
Is there somthing I need to change?
Ah, when you said it opened another window, I assumed it did so via javascript. Try this then:
in x.htm:
<SCRIPT language='javascript'>
self.name='xyz';
</script>
then in x1.htm:
function x()
{
var winxyz = window.open('','xyz'); // get a handle to xyz
winxyz.location=winxyz.loc ation.href ;
self.close();
}
in x.htm:
<SCRIPT language='javascript'>
self.name='xyz';
</script>
then in x1.htm:
function x()
{
var winxyz = window.open('','xyz'); // get a handle to xyz
winxyz.location=winxyz.loc
self.close();
}
ASKER
OK. Great it worked. Just post it as an answer and i will give you the points.
BTW is there anyway i can get IE not to ask the user if they want to close the window?
BTW is there anyway i can get IE not to ask the user if they want to close the window?
No. If the history array holds more than one entry, the warning will appear - thanks for that. I hate it when people try to close my browser window.
Michel
Michel
ASKER
well, I'm opening the window for a specific reason and want to close it immedeatly. I don't even want the user to notice that it opened!
Hmm - should not give a warning then.
In v4 browsers you can do this instead:
<FORM action="x1.htm" method=POST id=form2
name="LangCombo" target="xx">
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</FORM>
<IFRAME NAME="xx" WIDTH=1 HEIGHT=1 SRC="about:blank">
<LAYER NAME="xx" WIDTH=1 HEIGHT=1 SRC="about:blank">
</LAYER></IFRAME>
and use parent.location.reload(1); // 0 if from cache is ok
Michel
In v4 browsers you can do this instead:
<FORM action="x1.htm" method=POST id=form2
name="LangCombo" target="xx">
<INPUT type="submit" value="Submit" id=submit1 name=submit1>
</FORM>
<IFRAME NAME="xx" WIDTH=1 HEIGHT=1 SRC="about:blank">
<LAYER NAME="xx" WIDTH=1 HEIGHT=1 SRC="about:blank">
</LAYER></IFRAME>
and use parent.location.reload(1);
Michel
ASKER
well, in IE5 it worked great. perfetly. But when i loaded the page in Netscape 4.7 I got an alert: Alert! did not find a converter or decoder
when i closed the alert and hit the submit button a new window opened and kept refreshing itself over and over. I tried it on someone elses pc using Netscape 4.6 and the same thing happened!
when i closed the alert and hit the submit button a new window opened and kept refreshing itself over and over. I tried it on someone elses pc using Netscape 4.6 and the same thing happened!
Sorry, I am not familiar with the other problem you are having.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hmmm - very strange.
Michel
Michel
In the child window, you can get the parent to reload itself like this:
<SCRIPT language='javascript'>
if ( self.opener && !self.opener.closed )
self.opener.location=self.
</script>