I have the following code that when working correctly should open link 1 in the iframe, wait 3 seconds, then open link 2 in the iframe, wait 3 seconds, etc..
Currently it's skipping straight to the last value in the array (the last 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() {
for (var i = 0; i < document.links.length; i++) {
var linx = document.links[i].href;
// create a closure for 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>