I'm encountering an issue with my code that is supposed to open different links in an iframe one after the other, with a 3-second delay between each. However, it seems to be skipping directly to the last link in the array instead of following the intended sequence.
Are there any JavaScript experts who can help me troubleshoot this?
<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>