new window, close window and refresh parent
Moderator: General Moderators
new window, close window and refresh parent
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.
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.
- dstefani
- Forum Contributor
- Posts: 140
- Joined: Sat Jan 11, 2003 9:34 am
- Location: Meridian Idaho, USA
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:
And in the form tag:
And in the Opener (original) page
I need to get this to work in NS6-7 as well.
It must need a small workaround added.
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>Code: Select all
<form action="YourScript.php" method="post" onSubmit="return SubmitForm(this);">Code: Select all
<script language="JavaScript" type="text/JavaScript">
<!--
// main window name
window.name = 'main';
//-->
</script>It must need a small workaround added.
- dstefani
- Forum Contributor
- Posts: 140
- Joined: Sat Jan 11, 2003 9:34 am
- Location: Meridian Idaho, USA
To submit to the parent window, put this in the head of the child window:
Then the form tag needs to have the parent window instance name as the target:
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
Code: Select all
<script language="JavaScript" type="text/JavaScript">
<!--
self.opener.name = 'main';
// -->
</script>Code: Select all
<form name="form1" method="post" action="parentPage.php" target="main">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
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.
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.
- dstefani
- Forum Contributor
- Posts: 140
- Joined: Sat Jan 11, 2003 9:34 am
- Location: Meridian Idaho, USA
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
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
I've already had the close window javascript code.
I think I'm heading in the right direction:
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.
I think I'm heading in the right direction:
Code: Select all
<a href=index.php onClick="javascript:window.close();" target="main">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.
... Then...
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!
You need to do a timeout for the window close.
Code: Select all
function closeWin()
{
setTimeout("window.close();", 2000);
}Code: Select all
<input type="button" value="Close Window" onclick="closeWin();">Have a nice day!
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.
What can I do with the parent window to identify it? In example:
Code: Select all
<body name="parent">FINALLY.
Code: Select all
<a href="javascript:self.close();window.opener.location.href='PARENT_REFRESH_LOCATION'">close this window</a>