Click to See Complete Forum and Search --> : help with basic question


leontager
07-21-2003, 05:06 PM
I am trying to create a simple script which would rederect me to several different websites with a one second interval.

this is my code

<html>
<body>
<script language="JavaScript1.1">
{
var sites = new Array();
sites[0]="http://www.yahoo.com";
sites[1]="http://www.geocities.com";
sites[2]="http://www.google.com";

for(x=0;x<3; x++)
{
setTimeout("window.location.replace(sites[x])",1000)
}
}
</script>
</body>
</html>


This is my first time doing anything in javascript and I got this code from a few examples I found on the net. I can not understand what is wrong with it. Why doesn't it go to all three websites?

sumyounguy
07-21-2003, 05:10 PM
I'm assuming it only goes to the first webpage.
This is because as soon as the first webpage is loaded, the thread dies, since your webpage is closed i'm guessing it would work if you opened these sites in a new window

leontager
07-21-2003, 05:12 PM
well actually what happens is that the URL changes to
C:\my folder\undefined. How would you suggest doing this properly so it would change the URLs in the same window:confused:

Charles
07-21-2003, 05:24 PM
The first time you load a new page you overwrite your running script. You need to open the pages in a new window.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<script type="text/javascript">
<!--
sites = ['http://www.bettiepage.com/images/photos/bikini/bikini1.jpg', 'http://www.bettiepage.com/images/photos/bikini/bikini2.jpg', 'http://www.bettiepage.com/images/photos/bikini/bikini3.jpg', 'http://www.bettiepage.com/images/photos/bikini/bikini4.jpg'];

Array.prototype.next = function () {if (this.n == undefined || this.n >= this.length) this.n = 0; return this[this.n++]}

setInterval ("window.open(sites.next(), 'bettie')", 1000);
// -->
</script>

leontager
07-21-2003, 05:43 PM
thank you very much