PDA

View Full Version : Setting A Certain Delay



gabrola
10-25-2008, 10:37 PM
I need a function that will reload a page inside an iframe a number of times.
Example.
There is a form that has 1 input box and a button so I enter 10 in the box and click the button then for example a certain page will reload 10 times inside the iframe.
I was able to do that but the problem is i can't set it to wait for the page to load first, secondly i want it to reload the page as soon as the first part loads not the whole of it.

Thanks and please help
Here's my code


<script type="text/javascript">
var t = 0;
function StartRefresh(){
e = t;
if(t == document.form.how_many.value) {
counter.innerHTML="Finished";
} else {
t += 1;
counter.innerHTML=t;
document.getElementById('refreshed').src = 'example.com';
}
}
</script>
<FORM NAME="form">
# of Times?<INPUT TYPE="text" name="how_many"><br>
<br>
<INPUT TYPE="button" VALUE="Start" onClick="StartRefresh()">
<span id="counter"></span>
<iframe id="refreshed" height="100px" align="left" width="100px" frameborder=0 marginwidth=0 marginheight=0 src=""></iframe>
</FORM>

using settimout or setinterval will make it wait for a specified amount of time and i don't want that I want it to reload as soon as the page starts to reload

magicyte
10-26-2008, 12:02 AM
Loop it:


<script type="text/javascript">
function StartRefresh(){
for(i = 0; i < document.form.how_many.value; i++) {
document.getElementById('counter').innerHTML=i;
document.getElementById('refreshed').src = 'example.com';
}
document.getElementById('counter').innerHTML="Finished";
}
</script>
<FORM NAME="form">
# of Times?<INPUT TYPE="text" name="how_many"><br>
<br>
<INPUT TYPE="button" VALUE="Start" onClick="StartRefresh()">
<span id="counter"></span>
<iframe id="refreshed" height="100px" align="left" width="100px" frameborder=0 marginwidth=0 marginheight=0 src=""></iframe>
</FORM>

-magicyte

gabrola
10-26-2008, 02:49 PM
Well strangely it hits finished in a second so it doesn't wait for the page to finish or even start refreshing :(

magicyte
10-27-2008, 10:03 PM
It's supposed to. Do you want it to wait however many seconds?

-magicyte

gabrola
10-27-2008, 10:19 PM
Dude i don't want it to do it instantly neither wait a certain number of seconds i want it to wait for the iframe to finish refreshing before it starts the next refresh. Because some people may have a fast connection and some people have slow ones so I can't give a certain number of seconds.
btw I'm no newbie or anything in javascript it's just that thing that's hard :/

magicyte
10-27-2008, 10:21 PM
Impossible.

-magicyte

gabrola
10-27-2008, 10:24 PM
That's what I thought, anyway I thought of using interval and make each user select his own interval time

magicyte
10-27-2008, 10:30 PM
Do you want to do that? I'd be glad to code you something.

-magicyte

gabrola
10-27-2008, 10:33 PM
lol i did it already :P as I said i'm no noob =D
Anyway i thought about it and probably the only way to do it is use the onChange because I tried it and it waits for the page to load =D

gabrola
10-27-2008, 10:35 PM
But that would make it go on forever
Edit: actually not :P

magicyte
10-27-2008, 10:41 PM
So you are already done with it? Ok. Any questions and I'll help. I'm no noob either.

:D

-magicyte

gabrola
10-27-2008, 10:43 PM
Yep and my users love it :D
It's a facebook autoroller for an application