Forum Moderators: coopster

Message Too Old, No Replies

Manual refresh iFrame contents on PHP page: best way?

User-initiated, non-"meta tag" iFrame refresh

         

aragornking

4:19 am on Dec 2, 2003 (gmt 0)

10+ Year Member



Hi. I understand one can easily, and periodically, refresh an iFrame's contents using a meta tag. Though still new at this game, I can't seem to figure out, or find on the web, a means of manually refreshing an iFrame, e.g., creating a refresh button in the iFrame.

Basically, I am trying to refresh a PHP based file/image (in the iFRAME) in a PHP file. Can someome point me in the direction of a tutorial that includes this topic (I failed to find one), or suggest an approach I might follow? Thanks for reading this.

NickCoons

11:05 am on Dec 2, 2003 (gmt 0)

10+ Year Member



To do this automatically, you'd probably want to refresh the page in the iframe the same way you would a standard page, by putting meta http-equiv in the header of the iframed html page.

To do this manually, there are a couple of ways.. but I think you'd probably be looking at something javascript-based instead. My javascript is a little rusty since I don't use it often...

If you put a button in the iframe that you want to click to refresh it, then try window.location.reload() (among many other possibilities). If you put the button outside of the iframe, then you'll have to reference the frame by name. This may be top.[iframe-name].location.reload().

aragornking

9:17 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



Thanks for your reply. I tried the simple code below without success. The error I obtained for each test button was:

"Object doesn't support this property or method"

My test code:
<html>
<head>PHP in HTML
</head>
<body>
<h2><font face="arial" color="green"></font></h2><br><br>
<Iframe name=my_iframe
src="test_file.php" width="300" height="300">
</Iframe>

<form>
<input type="button" value="Reload" onClick="my_iframe.window.reload()">
<input type="button" value="Reload" href="#" onclick="window.frames['my_iframe'].reload(true)">

</form>

</body>
</html>

I must be overlooking something. Any ideas? Thanks.

aragornking

10:33 pm on Dec 2, 2003 (gmt 0)

10+ Year Member



I found out what I was doing wrong. The following worked as an external reload button (I changed "window" to "location"):

<input type="button" value="Reset code" onClick="my_iframe.location.reload()">

Thanks for your patience and help. I think I can live without a reload button within the iframe box.

eaden

11:35 am on Dec 4, 2003 (gmt 0)

10+ Year Member



you could also have a simple link in the iframe to iself with a?random=$randomcharacters at the end.

- make $randomcharacters with md5(time())

aragornking

5:45 am on Dec 7, 2003 (gmt 0)

10+ Year Member



Thanks Eaden.