Jump to content

Refresh individual iframes?


matfish

Recommended Posts

Hi, Iv got a simple standard page (html) with a few iframes which pulls in different stats (its a work related thing).

 

I want to update one of the iframes only. Putting a meta refresh within that one iframe still reloads the whole page.

 

Im new to Ajax, anyone know of how to refresh one 1 iframe on a timer?

 

Many thanks

Link to comment
Share on other sites

Refreshing with AJAX pretty much removes the need for the iframe.  Either way, all you need to do is use a javascript timer to call a refresh javascript function.  In your response function, simply restart the timer.

 

Play with the example here: http://www.phpfreaks.com/forums/index.php/topic,115581.0.html

 

Then once you've written some of the code yourself, ask again.

Link to comment
Share on other sites

From one frame you can target another frame

 

<iframe name="a" src="displayimage.php?imageid=1">

 

<iframe name="b" src="listofimages.php">

 

in file listofimages.php suppose you have a link

<a href="displayimage.php?imageid=<?php echo $imageid?>" target="a">

Link to comment
Share on other sites

Thank you both. I thought this would be an Ajax thing but javascript seemed to handle it:

 

<html>
<head>
<script type="text/javascript">

//Example to show 2 iframes, which the google iframe is being refreshed on its own

var reloadInterval = 3000;
function init() {
setTimeout('reload()',reloadInterval);
}

function reload() {
var iframe = document.getElementById('window1');
if (!iframe) return false;
iframe.src = iframe.src;
setTimeout('reload()',reloadInterval);
}

window.onload = init;
</script>

</head>
<body>

<iframe id="window1" width="500" height="400" src="http://www.google.com/"/></iframe>

<iframe id="window2" width="500" height="400" src="http://www.yahoo.com/"/></iframe>

</body>
</html>

Link to comment
Share on other sites

 iframe.src = iframe.src;

Done that before, and one thing I can tell you is that if the user uses the backpage afterwards, the results will be very ugly! The backpage will load the iframe src as the whole page. Definitely very confusing for the user.

 

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.