PDA

Click to See Complete Forum and Search --> : simple refresh


delta770
Feb 23rd, 2003, 11:30 PM
i have this code



<script language="JavaScript" type="text/JavaScript">
function RefreshMainWindow() {
window.opener.location.reload();
window.close()
}
</script>

//called by

<META HTTP-EQUIV="refresh" CONTENT="5; RefreshMainWindow();">




am i not allowed to call a method in a refresh block? how can i do something like this..

when the script runs, every 5 seconds, the parent refreshs, but the child windows (that this script is on) doesn't clse like it's supposed to, it refreshes too.. :(

--770

punkpie_uk
Feb 24th, 2003, 05:33 AM
when you open the window open it with a var name...


var newWin = window.open('page2.htm');


... the try doing newWin.close() instead.

Rick Bull
Feb 24th, 2003, 06:52 AM
Yes you can't use scripting in a meta refresh, I think you're looking for setTimeout():


<script type="text/javascript"><!--
window.setTimeout('RefreshMainWindow();', 5000);
//--></script>


Think that should work.

delta770
Feb 24th, 2003, 10:20 AM
i'm new to JS, so not exactly sure where to put the script Rick Bull gave, and how to call it....

or how to give the opening window a variable name...
this is how i'm currently opening a new window


target="_blank"


--770

Rick Bull
Feb 25th, 2003, 06:18 AM
You can put the code I gave either in the <head> section or the <body> section. I'd go with the head.

target="_blank" is find if you're just using standard links (which is better as not every browser supports JS). Other wise you can use javascript something like
var newWin = window.open('page.html', 'windowName');
Then you can use newWin with Javascript (e.g. newWin.close()) and target the new window with standard links like <a href="#" target="windowName">