I'm having problems with setTimeout. I've also tried setInterval. I wish JS just had a pause or sleep.
In theory, this code should write the first link from the array, wait 3 seconds, write the next, and so on. But it won't even call the function.
<html>
<head></head>
<body>
<a href="http://www.google.com">Google</a>
<a href="http://www.thinkgeek.com">ThinkGeek</a>
<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;
setTimeout("openLinks(linx)"),3000);
}
}
function openLinks(link){
document.write(link + "<br />");
}
window.onload = getLinksArray();
</script>
</body>
</html>
The second part of my question is to change the src of the iframe to the links (instead of writing them). I'm only using the document.write
for testing purposes to get the delay working.
I've tried document.getElementById("myid").src = link;
and it won't do anything at all. Almost as if the iframe doesn't even exist.
I'm not a pro, so I'm here hoping to get help from a pro. ;) Thanks in advance.