Hey
OK - there are 2 ways of doing this. The first way is the way you requested using Javascript on the page that hosts the IFRAME. I have written and tested the code and there is an example below.
However, the second method is the more accepted, "correct" method. This method involves using the meta refresh tag in the document that you wish to reload, ie the document that gets loaded into the IFRAME. Obviously if you are loading a page from another website into your IFRAME, you will not be able to change their page code, so the Javascript option is the only option you have. However, if the page being displayed and refreshed is under your control, I would strongly suggest using this method.
Simply include the following in the HEAD of your document:
CODE
<meta http-equiv="refresh" content="3">
That will tell you browser to refresh the page every 3 seconds. Simple!
If you have to use the Javascript method, you can try the code below. I have included the code of the whole test page, so you can copy and paste this into a new .htm document and run it immediately:
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pl" xml:lang="pl">
<head>
<title>Javascript IFrame Reload</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript"><!--
// set your interval in milliseconds
var reloadInterval = 3000;
// this will run when the document is fully loaded
function init() {
setTimeout('reload()',reloadInterval);
}
// this reloads the iframe, and triggers the next reload interval
function reload() {
var iframe = document.getElementById('reloader');
if (!iframe) return false;
iframe.src = iframe.src;
setTimeout('reload()',reloadInterval);
}
// load the init() function when the page is fully loaded
window.onload = init;
--></script>
</head>
<body>
<iframe id="reloader" width="500" height="400" src="http://www.google.com/"/>
</body>
</html>
Hope that helps.