By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,144 Members | 849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,144 IT Pros & Developers. It's quick & easy.

How hard can it be to reload the main window ?!?!!?

P: n/a
Hi all,

I'm trying to reload a frame from a pop-up, but really cannot figure
this out.

Within my index.htm file, I make a link to call a pop-up frame with a
javascript function that calls the following code from an external
javascript source file, dynamically created with PHP

document.write('<a href="javascript:void(0);"
onclick=\'win1=window.open("http://127.0.0.1/comments.php?site_name=<?php
echo $site_name;?>&linker='+linker[argument]+'", "devWindow",
"height=450,width=420,screenX=0,left=50,screenY=0, top=100,location=0,menubar=0,scrollbars=1,status=0 ,toolbar=0",
"option2") ;win1.focus(); \' target="">'+href+'</a>');

Within the pop-up window, I use the following code
----> Head section

<script type="text/javascript">
cleanup () {
opener.location = opener.location.href;
opener.location.reload();
}
</script>
</head>

<body class="body" marginheight="0" marginwidth="0"
onUnload="cleanup()">

I want the file index.php to reload when the pop-up is closed down. I
seem to have tried every variation of opener.reload(), but still can't
manage it solve it.

Can anyone see what I am doing wrong ?

I'm starting to pull my hair out.....
Rgds
Neil.
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 17 Feb 2004 05:55:03 -0800, sentinel <ne**@sentinel.f9.co.uk> wrote:
Within my index.htm file, I make a link to call a pop-up frame with a
javascript function that calls the following code from an external
javascript source file, dynamically created with PHP

document.write('<a href="javascript:void(0);"
onclick=\'win1=window.open("http://127.0.0.1/comments.php?site_name=<?php
echo $site_name;?>&linker='+linker[argument]+'", "devWindow",
"height=450,width=420,screenX=0,left=50,screenY=0, top=100,location=0,menubar=0,scrollbars=1,status=0 ,toolbar=0",
"option2") ;win1.focus(); \' target="">'+href+'</a>');
I'm not going to check too hard if that's syntactically correct. You
should only post client-side code, replacing server-side code with what
might be generated. Formatting your posts with indentation and controlled
line-breaks (rather than newsreader wrapping) would also be helpful.
However, I will say this:

Don't use the JavaScript pseudo-protocol (href="javascript:...") unless
there is a good reason to. In this case, it isn't much of a problem as
non-JavaScript users won't even see that link, but for other cases, one
should consider alternative approaches, such as,

- Buttons
- <a href="" onclick="<code>;return false;"
- <a href="page.html" target="someWindow"
onclick="window.open('page.html','someWindow');ret urn false"
<script type="text/javascript">
cleanup () {
Syntax error. Should be:

function cleanup() {
opener.location = opener.location.href;
opener.location.reload();
}
</script>
</head>

<body class="body" marginheight="0" marginwidth="0"
onUnload="cleanup()">

I want the file index.php to reload when the pop-up is closed down. I
seem to have tried every variation of opener.reload(), but still can't
manage it solve it.


Other than that syntax error, the problem could be that the onunload event
isn't firing. Onunload is unreliable, at best. I know for a fact that
Opera only fires it when the page is changed. Closing the tab, window, or
refreshing the page does nothing. Mozilla fires it when the page is
changed or refreshed, but not when closed. Netscape and IE fire it when
the page is changed, refreshed or closed. That's only four browsers, all
of which displaying different behaviours, amongst a hundred.

If this refreshing is critical, it might be worth integrating the pop-up
window into the main page, then using a link to go to another page.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2

P: n/a
KD
This worked for me:

function cleanup()
{
// This is done in the following way because Mozilla does not
// want to obey the simpler .reload() function.
// window.opener.location.reload(); -- Mozilla Bug

var originalLocation = window.opener.location;
window.opener.location.href = originalLocation;
window.close();
}

Michael Winter wrote:
On 17 Feb 2004 05:55:03 -0800, sentinel <ne**@sentinel.f9.co.uk> wrote:
Within my index.htm file, I make a link to call a pop-up frame with a
javascript function that calls the following code from an external
javascript source file, dynamically created with PHP

document.write('<a href="javascript:void(0);"
onclick=\'win1=window.open("http://127.0.0.1/comments.php?site_name=<?php
echo $site_name;?>&linker='+linker[argument]+'", "devWindow",
"height=450,width=420,screenX=0,left=50,screenY=0, top=100,location=0,menubar=0,scrollbars=1,status=0 ,toolbar=0",

"option2") ;win1.focus(); \' target="">'+href+'</a>');

I'm not going to check too hard if that's syntactically correct. You
should only post client-side code, replacing server-side code with what
might be generated. Formatting your posts with indentation and
controlled line-breaks (rather than newsreader wrapping) would also be
helpful. However, I will say this:

Don't use the JavaScript pseudo-protocol (href="javascript:...") unless
there is a good reason to. In this case, it isn't much of a problem as
non-JavaScript users won't even see that link, but for other cases, one
should consider alternative approaches, such as,

- Buttons
- <a href="" onclick="<code>;return false;"
- <a href="page.html" target="someWindow"
onclick="window.open('page.html','someWindow');ret urn false"
<script type="text/javascript">
cleanup () {

Syntax error. Should be:

function cleanup() {
opener.location = opener.location.href;
opener.location.reload();
}
</script>
</head>

<body class="body" marginheight="0" marginwidth="0"
onUnload="cleanup()">

I want the file index.php to reload when the pop-up is closed down. I
seem to have tried every variation of opener.reload(), but still can't
manage it solve it.

Other than that syntax error, the problem could be that the onunload
event isn't firing. Onunload is unreliable, at best. I know for a fact
that Opera only fires it when the page is changed. Closing the tab,
window, or refreshing the page does nothing. Mozilla fires it when the
page is changed or refreshed, but not when closed. Netscape and IE fire
it when the page is changed, refreshed or closed. That's only four
browsers, all of which displaying different behaviours, amongst a hundred.

If this refreshing is critical, it might be worth integrating the pop-up
window into the main page, then using a link to go to another page.

Mike

Jul 20 '05 #3

P: n/a
KD wrote:
This worked for me:

function cleanup()
{
// This is done in the following way because Mozilla does not
// want to obey the simpler .reload() function.
// window.opener.location.reload(); -- Mozilla Bug
There is AFAIS no Mozilla bug (any more).
var originalLocation = window.opener.location;
window.opener.location.href = originalLocation;
No need for the variable.
window.close();
}

[Top post]


Please do not do that.
PointedEars
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.