DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   Iframe reload with setTimeout (http://www.daniweb.com/forums/thread145743.html)

Dalli Sep 14th, 2008 2:44 pm
Iframe reload with setTimeout
 
Hello,
I have a problem with something very simple, but because of my 0 knowledge in js, i can't understand what am i doing/thinking wrong. I have one main site, that have 2 small iframes in between everything else. In the second iframe i have a form, when i submit the form, i need the first iframe to be reloaded with delay so it can read the updated info from database.
So, in the second (with the form) iframe i have the code:
<head><script type="text/javascript">
function f() {
  parent.mini.location.reload();
}
function r() {setTimeout(f(),2000);
}
</script>
</head>
and on the submit button on the form i have onclick="r()"
This reloads the mini iframe right away and gives Useless setTimeout call (missing quotes around argument?) in FF error console. I tried having some simple examples of setTimeout function, but still didn't get it to work. Tried also with every single syntax i could find online, with no result. Does anybody have any suggestions on what i should/could do?

essential Sep 14th, 2008 11:36 pm
Re: Iframe reload with setTimeout
 
This is why, you keep on getting those error-->

function r() { setTimeout(f(),2000); }
You forgot to quote it.
setTimeout("f()", 2000)

And here's my quick example about reloading those iframes' on your page! Hope it helps you... Good day..

<html>
<head>
<title><!--Sample--></title>
<script type="text/javascript">
function f()
{
   
var refresh = document.getElementById('frame1');
/* You can also use -->
  refresh.contentWindow.location.reload( true );
  but not all browser support this function!
  So i wil just perform a simple trick to get things done... Enjoy
  Code is as follows:
 */
  timer = setTimeout('f()', 1000);
if ( timer == 5 ) { clearTimeout( timer );
refresh.src = 'yourpage.html#'; //or you can just set this = refresh.src
 
}
}
</script>
</head>
<body>

<div>
<iframe id="frame1" src="yourpage.html"></iframe></div><br />
<input type="button" value="click" onclick="f()" />
</body></html>


All times are GMT -4. The time now is 2:48 am.

Forum system based on vBulletin Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
©2003 - 2010 DaniWeb® LLC