Reloading an iFrame?

liunx

Guest
Can anyone tell me how to reload/refresh an iFrame within a page? say every 5 seconds?<br />
<br />
I don't want the whole page to reload just the iFrame. Also is it possible to reload layers such as DIV or SPAN?<br />
<br />
<IFRAME name="frame" src=http://www.htmlforums.com/archive/index.php/"data.htm" width="400" height="400"></IFRAME><!--content-->My guess is you would use the usual code for refreshing a page (see below) and put it between the <head> tags in the iframe source code.<br />
<br />
<META HTTP-EQUIV="refresh" content="5;URL=iframe.htm"> <br />
<br />
I have never tried that though so it may not be as simple as that. Worth a try though! ;)<!--content-->Sorry that refreshes the whole page, I need some code to refresh just the iframe. Maybe javascript would do the trick?<!--content-->Are you sure you put the code in the right place? I just tried it and it worked fine. The code must go between the <head> tags in the iframe file, not the file for the main page.<br />
<br />
I'm sure you probably can do it with javascript too but I don't know how.<!--content-->I see what you mean but what i'm trying to achieve is a little different, I don't want to refresh either page (main or data source) just the actual iFrame within the main page. Meta refresh reloads a whole page, whereas I just want to reload a frame inside a page.<!--content-->Put the meta refresh tag inside the file that goes inside the iframe.<!--content-->Give the iframe element a name and then execute following from the main page:<br />
<br />
<script language="javascript"><br />
<br />
function refreshTimer(){<br />
top.iframename.location.reload();<br />
}<br />
<br />
setInterval("refreshTimer()",2000);//refresh every 2 seconds<br />
</script><br />
<br />
Alternatively:<br />
<br />
<script language="javascript"><br />
<br />
function refreshTimer(){<br />
var url = document.getElementById('frameid').src;<br />
document.getElementById('frameid').src = <!-- m --><a class="postlink" href="http://www.htmlforums.com/archive/index.php/url;">http://www.htmlforums.com/archive/index.php/url;</a><!-- m --><br />
}<br />
<br />
setInterval("refreshTimer()",2000);//refresh every 2 seconds<br />
</script><!--content-->Perfect! thanks kdjoergensen just what I was looking for :) Is it possible to do the same javascript code with layers such as DIV or SPAN?<br />
<br />
Thanks again everyone ;)<!--content-->No, reloading <div> and <span> is not possible without loading the whole page.<!--content-->I tried refreshing the iframe and expected the data source page to load smoother (flicker and click free) than meta refresh. However when I tried it the iframe reloads slowly. As I am attempting to make a chat room in ASP I want a window to display messages without the usual flicker or clicking. This was achieved on PULPchat (<!-- m --><a class="postlink" href="http://www.pulpchat.com/">http://www.pulpchat.com/</a><!-- m -->) so how do they do it?<br />
<br />
Can anyone suggest a better solution to making a HTML based chatroom? or even point me in the direction of some source code?<!--content-->to get a flicker free refresh you need to be reloading very little. it all depends on your connection and how much is in the page you are reloading. using javascript or the meta tag refresh does the samething. and sometimes it just loads from cache. so if you have a lot of code to refresh then it will flicker no matter what<!--content-->It's not so much the flicker i'm concerned about with meta refresh it's the clicking, it's enough to drive anyone insane! PULPchat (<!-- m --><a class="postlink" href="http://www.pulpchat.com">http://www.pulpchat.com</a><!-- m -->) has got around it somehow, they've got a HTML based chat room that is flicker and click free. I'm not sure how they did it but I want the same results.<!--content-->the clicking sound is your computer. it is the default sound for it. It is not the site that is doing it. I don't remember anything else that will refresh a page so that must be what they are doing.<br />
<br />
also I am not signing up for something to jsut look at the source.<!--content-->I know the sound is a default on the computer, why would I think it comes from the site? :confused: <br />
<br />
Well i've just found this code which refreshes a page without the clicking:<br />
<br />
<html><br />
<head><br />
<title>Chat Input</title><br />
<script language="JavaScript"><!--<br />
function Reload() {<br />
window.location.reload(true);<br />
}<br />
<br />
function DoPageLoad() {<br />
<br />
var Timer = setTimeout('Reload()', 5000);<br />
}<br />
// --></script><br />
<base target="_self"><br />
</head><br />
<body bgcolor="#FFFFFF" marginwidth="0" marginheight="0" topmargin="0" leftmargin="0" onLoad="DoPageLoad();"><br />
<p><span id="BGOutput">Here is the page content</span></p><br />
</body><br />
</html><br />
<br />
:rocker:<!--content-->
 
Back
Top