Javascript: how do i load all the links in the html to the same window one after another in an interval of a few seconds
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/13133075/javascript-how-to-open-a-page-then-wait-for-few-seconds-open-another-page-in-th">Javascript: how to open a page then wait for few seconds open another page in the same window</a>  </p>
</blockquote>



<p>I tried to load all the links in the html to the same window. However only the first link gets loaded. I got an error message saying webpage undefined in Chrome. Can someone please help me because i am pretty new in Javascript. Thanks. The code is as follows:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script&gt;

window.onload=function(){myFunction()};

function myFunction()
{
var links = document.links;

mywin=window.open("","mywindow");
mywin.location=links[0];
for(var i = 1; i &lt; links.length; i++)
{
    setTimeout(function(){mywin.location=links[i];},5000);
} 
}

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;&lt;a href="http://www.yahoo.com"&gt;yahoo&lt;/a&gt;&lt;/h1&gt;
&lt;h1&gt;&lt;a href="http://www.youtube.com"&gt;youtube&lt;/a&gt;&lt;/h1&gt;
&lt;h1&gt;&lt;a href="http://www.google.com"&gt;google&lt;/a&gt;&lt;/h1&gt;
&lt;/body&gt;
&lt;/html
</code></pre>
