PDA

View Full Version : Javascript - Refresh Parent Window?



cancer10
08-09-2008, 07:25 AM
Hi

I have an HTML page (index.html) and a link in it. Clicking on that link opens a javascript Popup (popup.html). There is a small form on the popup window. Now when someone submits the form in that popup.html page, the index.html should refresh automatically.

Anyone knows how to do this?


Please help me.


Thanx

rangana
08-09-2008, 09:00 AM
On popup.html:


<a href="#" onclick="window.opener.document.location.reload(true);return false;">Refresh Parent</a>

cancer10
08-09-2008, 09:03 AM
Question:

Can this be used after the form is submitted? Or this needs to a click event to operate?

jscheuer1
08-09-2008, 09:14 AM
You can use the form's submission:


<form action="whatever" onsubmit="window.opener.location.reload();">

If the opening window already has a name, you may even target the form to that window, loading whatever page (the form's action attribute) you like into that window. Doing so will send the form's post or get data to that page. It can even be the same page that was in that window, in which case it would be like a refresh.

The only problem with any of this though is that without javascript enabled, unless you use frames or iframe(s), there is no way to be sure of a way to target a particular window. Even then (with some sort of frame, and/or using javascript), your imagined target may have been closed by the user before you get a chance to reload it or whatever.

enisonica
08-15-2008, 01:34 PM
I have problem here. Popup window is opened from one frame. On closing the popup window I want to refresh/reload whole page (not just frame from which popup window was opened). How do I do that?

I've put:
function closeReload() {
opener.location.reload();
self.close();
}
but it relaods only one frame, not the whole page.

The page that is supposed to be reloaded is index.html.
I have 3 frames in total. Should I somehow reload each of them. I've tried putting this:


function closeReload() {
top.document.frames[0].location.reload();
top.document.frames[1].location.reload();
top.document.frames[2].location.reload();
self.close();
}

but it's not working :(

Anyone?

jscheuer1
08-15-2008, 03:11 PM
The frameset and the pop up page must be on the same domain:


window.opener.top.location.reload();

However, what do you expect to happen? This will refresh the opening page's top frameset. What this means is that in FF the pages currently in that frameset will reload. In IE they will go back to their starting pages.

If you want to always reset the pages in the frameset to their starting pages, you would have to specify the location (still requires frameset and pop up page on the same domain):


window.opener.top.location = 'name_of_the_frameset.htm';

If the path to the frameset is different than the path of the pop up, it should be given along with the filename.

To get them to always just refresh their current pages, even in IE - that's a little tricky:


function refreshOpenerTopFrameset(){
var f = window.opener.top.frames;
for (var i = f.length - 1; i > -1; --i)
f[i].location.reload();
}

And that will only work if all the pages in the frameset, the pop up page, and the frameset page are on the same domain.