Click to See Complete Forum and Search --> : Waiting for...


halifaxrick
08-27-2003, 09:35 AM
Hi, I am new the the forum, so sorry if I am bothering anyone.

As most people new to the forum, I have a question :) , so I will cut the crap and ask it.

I have a Javascript function (below) that works exactally as I want it to, except it works too quickly. Is there anything that I can put at the start of the function to enduce a pause (while a directory listing in another frame loads).

function reload_all() { window.parent.main.location.href = "main.htm";}

The page is http://www.babyoctopus.com/babastuff/html
(sorry about all the baby pics, it's to keep the granparents happy.)
The frame in the top right controls the bottom left frame and a hidden frame at the bottom. When one of the links is pressed, the hidden frame changes to the directory requested, and the bottom left frame is reloaded to reflect the directory change. I currently have tried to slow the function down by making it reload a couple of pages before the correct one, like so.

function reload_all() { window.parent.main.location.href = "loading.htm"; window.parent.main.location.href = "loading.htm"; window.parent.main.location.href = "main.htm";}

The function is performed by an OnClick.

Thanks in advance, Rick.

halifaxrick
08-27-2003, 12:28 PM
I decded to search the forum to see if any other problems were similar. I found that there is the setTimeout parameter. would this work?
If it does work should I use it as part of the onClick like so, or something else?


if (i - 13 == 0) {document.write('<TD width=50><center><A HREF="'+link+'" onClick="setTimeout("reload_all()", 5000)"

with the function reload all as above?

function reload_all() {window.parent.main.location.href = "main.htm";}

David Harrison
08-27-2003, 12:59 PM
You can use setTimeout like this:

function reload_all(){
window.parent.main.location.href = "main.htm";
}

function wait(){
window.setTimeout("reload_all()",1000);
}


onclick="wait();return false;"

The 1000 sets a delay of 1 seconds, 2000 would set a delay of 2 seconds etc.

Edit: You could change wait so that it looked a little like this:

function wait(func){
window.setTimeout(func,1000);
}

and then for the onclick have:

onclick="wait('reload_all()');return false;"

This would mean that you could use the function wait to set a delay for any function, by passing it the arguement of the function you want to delay.

halifaxrick
08-27-2003, 01:57 PM
The wait() function worked really well, (1.5 second delay)

I tried to use the onclick="wait('reload_all()');return false;" version, but it kept giving me javascript errors. (It expected a ) immidiatly after the wait(.

I have had that problem before and I think it is because the onClick is nested within a document.write.


Thanks again, my parents and parents-in-law will be very happy.:)

David Harrison
08-27-2003, 02:05 PM
I think I know what you're problem is, try this:

document.write('<td width=50 align="center"><a href="'+link+'" onclick="wait(\'reload_all()\');return false;">'+link+'</a></td>');


When you use " and ' use them like this:

" ' \" \' and close them \' \" ' "

or:

' " \' \" and close them \" \' " '