Javascript - Problems with Loop with Array -



Javascript - Problems with Loop with Array -

i have next code when working correctly should open link 1 in iframe, wait 3 seconds, open link 2 in iframe, wait 3 seconds, etc..

currently it's skipping straight lastly value in array (the lastly link).

any js expert takers?

<html> <head></head> <body> <a href="http://www.google.com">google</a><br /> <a href="http://www.thinkgeek.com">thinkgeek</a><br /> <a href="http://www.themetapicture.com">the meta picture</a> <iframe src="http://www.google.com" id="myid" name="main" width="1024" height="768"> </iframe> <script> function getlinksarray() { (var = 0; < document.links.length; i++) { var linx = document.links[i].href; // create closure each loop iteration (function(linx) { settimeout(function() { openlinks(linx); }, 3000); }(linx)); } } function openlinks(link) { document.getelementbyid("myid").src = link; } window.onload = getlinksarray(); </script> </body> </html>

i'm pretty sure should trick, without creating longer , longer delays. haven't performance tested both though, can't best - wanted create sure aware of option.

var linx = document.links; (function loadlink(i) { settimeout(function () { document.getelementbyid("myid").src = linx[i].href; if(linx[++i]) { loadlink(i); } }, 3000) })(0);

javascript arrays loops iframe

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -