Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with For Loops and iFrames Please

Status
Not open for further replies.

wellmoon

Technical User
Dec 6, 2006
28
GB
Hi,

I want to load a series of pages into an iFrame and then do something with the contents. The following code works fine with just one page loaded into the iFrame:
function loadDocs() {
frames("docframe").location.href = docs[0];
setTimeout("doNextFunction();", 1000);
}
Like I say, this works fine and calls the next function after ample time for the iFrame doc to load. However, docs is an array and as soon as I put the above code into a for loop so that all items in the array can be loaded (one after the other with doNextFunction() acting on all of them), it stops working. This is what I have tried:
function loadDocs() {
for (x = 0; x < docs.length; x++) {
frames("docframe").location.href = docs[x];
setTimeout("doNextFunction();", 1000);
}
}

Anyone see what I'm doing wrong? Any pointers would be *hugely* appreciated
 
This is either Javascript or ASP not HTML perhaps you should ask this in the appropriate forum:

Javascript: forum216
ASP: forum333

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Surely your loop is just going to load all the pages, in quick succession, into the same <iframe>? Then all the doNextFunction()s are going to start running a second later and apply to the last page in the array.

What you need to do is take the loop out and just load the first page in the sequence. You pass the sequence number of that page as a parameter to doNextFunction():
Code:
function loadDocs() {
    frames("docframe").location.href = docs[0];
    setTimeout("doNextFunction(0);", 1000);
}
If the parameter's called x, you add a check to the end of doNextFunction() to see if there's a value at docs[x+1]. If there is, you load it into the iframe and queue up another run of doNextFunction() (passing it x+1 as a parameter).

That should do the trick.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top