...

View Full Version : reload parent on pop-up unload



conspiracyx
07-15-2004, 12:05 AM
i have been trying to find a way to make JS to something (explained below) but it doesnt work. does anyone have any suggestions?

the parent window opens a pop-up via JS. parent window may optionally have its name set to "main" (window.name = "main"). when the user closes the pop-up (like by clicking the "X" on the titlebar in Windows) the pop-up executes code to refresh the parent window.

any help would be nice, thanks in advance

sad69
07-15-2004, 12:16 AM
In body tag of your popup window, try this: (untested)


<body onUnLoad="window.opener.location.reload(1);">


But I'm pretty sure that will work.. let me know.

Sadiq.

SlySecretSpy
07-15-2004, 12:25 AM
This is unreliable in IE. Its a special feature that MS added(also known as a flaw).

I'd recommend instead adding an onFocus event handler right before the pop-up is created. Then when ever they focus back on the generating page, it can use that onFocus to check if the pop-up elemnt is there.

I'll code it up for you in a second.

conspiracyx
07-15-2004, 12:33 AM
oo...thanks a lot and thats for the code you are doing
btw...do u know why IE show the directory of the file (pop-up) in the pop up when i have this:

function reloadMainPage ()
{
window.opener.location.reload(false);
}

somewhere in the head and this for a link in the pop-up:

<a href="" onclick="javascript:reloadMainPage();">Click here to reload main
page</a>

SlySecretSpy
07-15-2004, 12:55 AM
Sorry this took a bit, had some work stuff to attend to, heh.


<script>
function focuser()
{
window.open('filetoopen.extnsion','windowname','params');
window.onfocus = checklive;
}
function checklive ()
{
window.location.reload();
}
</script>
<a href="#" onClick="focuser()">Link for pop-up</a>

conspiracyx
07-15-2004, 01:06 AM
um...i am sorta lost how it works
well from "window.onfocus = checklive;" down


is it possible to
1. generate a pop-up
2. when the pop-up is out of focus, make the parent check if the pop-up still exists and have a conditional
if (pop-up is closed)
then refresh yourself (parent)
end if


sorry, i still trying to explain things in a sorft of VBish way

glenngv
07-15-2004, 07:41 AM
Didn't sad69's suggestion work?

<body onUnLoad="window.opener.location.reload(1);">

It can be modified a bit to ensure that the opener is still open before reloading it.

<body onunload="if (opener && !opener.closed) opener.location.reload(1);">

Or you can't use it because the popup navigates to other pages too?

SlySecretSpy
07-15-2004, 04:59 PM
onUnload doesn't seem to respond correct in IE

If you do a google search you will find multiple people backing this up, or you can try it yourself :)

conspiracyx
07-15-2004, 05:47 PM
aight i will look aroung with Google. i still think the average user will probably click a link to close the pop-up using the link rather than the ( X ) and its a minor inconvenience with this IE 'feature' anyways

<3 firefox

SlySecretSpy
07-15-2004, 06:57 PM
My method seems to work. It reloads when ever you regain focus on your main page.

CodeCrazy
08-24-2004, 08:00 PM
I too, was having this same problem. The solution provided by SAd69 does indeed work. It even works for a window that's part of a frameset.

Thanks SAd69 for the help.

CodeCrazy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum