Jump to content

Meta refresh problem


rgrne

Recommended Posts

The following code may look simplistic and what it does may seem silly, but it is an attempt

to reduce a problem I'm having to the simplest possible form. If I can get the following code to operate the way I want, I will have found a way to solve a much more complicated problem:

 

I have two iframes, called 'testbox1' and 'testbox2'

 

Testbox2 initially displays a static page (just call it page.html).

 

Testbox1 runs the following php script (called subframetest.php) with some javascript embedded in it:

 

<?PHP

if ($n==5){

$n=0;

print "<meta HTTP-EQUIV=\"REFRESH\" CONTENT=\"1; URL=javascript:window.open('handlesound.php','testbox2');\">";

}

$n=$n+1;

print "<meta http-equiv=\"refresh\" content=\"4;URL=subframetest.php?n=$n\" />";

?>

 

What I am attempting to do is this:

 

The second meta refresh statement keeps refreshing this script in testbox1.  Each time, the variable $n gets incremented by 1.  When $n finally equals 5, the first meta refresh statement, in the if conditional, is activated.  The javascript in that statement causes another page (handlesound.php) to load into testbox2.  The script in textbox1 is supposed to *keep running* after that, so that every time $n gets back up to five, the handlesound.php is reloaded into testbox2. 

 

What's really happening is that the first time the meta refresh statement in the if conditional runs, it loads the new frame into testbox2 just fine, but the script in testbox1 stops running. I get the statement "[object Window]" printed in testbox1.

 

Is there a way to get the script in testbox1 to keep running after it loads a new page into testbox2? Maybe by using something other than meta refresh statements?

 

In an nutshell, I need to have a script in one iframe running repeatedly and continuously and checking the value of a variable each time.  If the variable takes on a certain value, it causes a new page to load into a second iframe. When that happens, the script in the first iframe must keep running and keep checking the value of the variable, so that when the variable takes on that certain value again, the page is reloaded into the second iframe again, ad infinitum.

 

Thanks in advance for any help and ideas.

 

 

 

Link to comment
Share on other sites

I think you can avoid using META refreshes by using Javascript to update the iframe source parameter on the fly.. I found this page which seems to have some useful information on how to do this: http://www.quirksmode.org/js/iframe.html

 

Basically, you can set the document.getElementById('testbox2').src or frames['testbox2'].location.href syntax to load a new page into the second iframe.. You could code this into a loop and probably avoid the need to refresh the PHP page at all, but you might still want to run the PHP page with an updated $n value each time for whatever reason, so you could still do that by using a header("Location: subframetest.php?n=$n") type of call instead of the META refresh stuff..

 

Link to comment
Share on other sites

Thanks.  I've been experimenting a bit with

document.getElementById('testbox2').src="handlesoundplayer.php"

in various places.  I can get this type of statement to reload the iframe called testbox2 from

its parent window, but if I put it into the script running in textbox1, it doesn't seem to recognize

testbox2 - it doesn't do anything.  This is true even when testbox1 is createdafter testbox2. Any ideas about this?

 

PS: I'm totally new at Javascript - this is the first time I've tried to use it.

 

 

Link to comment
Share on other sites

Hmm, yeah, I'm not sure what the best way to refer to that window would be or if it can even be done from within a separate iframe, but it seems like it should be possible.. Hopefully someone else here has a suggestion on how to do it..

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.