Page 1 of 1
new window, close window and refresh parent
Posted: Sun Mar 02, 2003 10:28 pm
by phice
I've got a forum I'm making that when you click a link, it opens a slightly formatted window, allows the user to post, and click a link to close the window.
But, the problem is that I need the parent window (where the user clicked the link to open the new, formatted window) to refresh to a page I request.
Any way to go about doing this? I've seen it done a few times, but not exactly sure how I'd do such a thing.
Posted: Mon Mar 03, 2003 5:05 am
by patrikG
opener.location.href='yourURL';
Posted: Wed Mar 05, 2003 11:22 am
by dstefani
I am trying to do the same thing.
I have had success with this, but ONLY IN IE! (Arrrg)
In the head of the popup:
Code: Select all
<script language="JavaScript" type="text/JavaScript">
<!--
function SubmitForm(theForm) {
var parent_ref = opener;
parent_ref.name = 'main';
theForm.target = 'main';
window.close();
}
// -->
</script>
And in the form tag:
Code: Select all
<form action="YourScript.php" method="post" onSubmit="return SubmitForm(this);">
And in the Opener (original) page
Code: Select all
<script language="JavaScript" type="text/JavaScript">
<!--
// main window name
window.name = 'main';
//-->
</script>
I need to get this to work in NS6-7 as well.
It must need a small workaround added.
Posted: Mon Mar 17, 2003 9:33 am
by phice
I've got the submit button going to another page in the same window. I need the code for a <a tag, which will close the window, then refresh the main page to the specified page.
Posted: Thu Mar 20, 2003 5:54 pm
by phice
anyone?
Posted: Thu Mar 20, 2003 7:11 pm
by dstefani
To submit to the parent window, put this in the head of the child window:
Code: Select all
<script language="JavaScript" type="text/JavaScript">
<!--
self.opener.name = 'main';
// -->
</script>
Then the form tag needs to have the parent window instance name as the target:
Code: Select all
<form name="form1" method="post" action="parentPage.php" target="main">
You can find a close window snippet onLine all over the place.
As far as closing the window after submit, it won't happen. NS cancels the submit and closes the window.
Sorry I can't be of more help, gotta' go.
dstefani
Posted: Fri Mar 21, 2003 12:24 am
by phice
Just to clarify any misunderstanding:
The main page is viewed, the user decides to reply to the post, and a new window opens. The form is inside the new window. The user inputs whatever it needs, hits submit, and page is loaded stating "Post has successfully been inserted...", followed by a link "Close window", which will close the window when clicked.
What I need is for the last link to refresh the Main page and close the small window.
Posted: Fri Mar 21, 2003 7:54 am
by dstefani
So when you say "refresh the main page" you mean, display the information just sent from the form in the popup window?
That's the easy part. The code I sent you in my last reply does just that.
You'll need to put a close button in your popup for the user to manually close the popup form page. You cannot (to my knowledge) do a submit and a close window in the same onSubmit action. I did a bunch of research on just this problem 2 weeks ago.
Test your close window button on a Mac, it doesn't work the same as on PC's. I'm sure you can find that info online.
I hope this is relevent.
dstefani
Posted: Fri Mar 21, 2003 2:32 pm
by phice
Ok, I just need a link that will close the window (brought up by the main window), and make the main window go to another page.
Posted: Fri Mar 21, 2003 3:17 pm
by dstefani
<form>
<input type=button value="Close Window" onClick="javascript:window.close();">
</form>
or <a href="javascript:window.close();">Close Window</a>
I don't know if this will work on Mac.
d
Posted: Fri Mar 21, 2003 3:46 pm
by phice
I've already had the close window javascript code.
I think I'm heading in the right direction:
Code: Select all
<a href=index.php onClick="javascript:window.close();" target="main">
It does what it's supposed to do, except it opens a new window, instead of making the main window go to "index.php". Is there something I need to do to the main window to name it, so I would send the target location directly to that window.
Posted: Mon Mar 24, 2003 8:22 pm
by Skyzyx
window.close() DOES work on any browser that properly supports JavaScript 1.3 (which is most these days).
You need to do a timeout for the window close.
Code: Select all
function closeWin()
{
setTimeout("window.close();", 2000);
}
... Then...
Code: Select all
<input type="button" value="Close Window" onclick="closeWin();">
Remember to be a good little web coder. Always quote your values, and don't use the "javascript:" pseudo-protocol in event handlers like "onclick". Also event handlers like "onclick" and "onsubmit" should be lowercase if you ever want to validate your pages as XHTML.
Have a nice day!
Posted: Mon Mar 24, 2003 10:10 pm
by phice
Thanks for the tips
What can I do with the parent window to identify it? In example:
..so that any target pointed to "parent" will load the specified location.
Posted: Mon Mar 24, 2003 10:23 pm
by phice
FINALLY.
Code: Select all
<a href="javascript:self.close();window.opener.location.href='PARENT_REFRESH_LOCATION'">close this window</a>