/    Sign up×
Community /Pin to ProfileBookmark

help with basic question

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?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@sumyounguyJul 21.2003 — 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
Copy linkTweet thisAlerts:
@leontagerauthorJul 21.2003 — well actually what happens is that the URL changes to

C:my folderundefined. How would you suggest doing this properly so it would change the URLs in the same window?
Copy linkTweet thisAlerts:
@CharlesJul 21.2003 — [font=georgia]The first time you load a new page you overwrite your running script. You need to open the pages in a new window.[/font]

[font=monospace]<!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>[/font]
Copy linkTweet thisAlerts:
@leontagerauthorJul 21.2003 — thank you very much
×

Success!

Help @leontager spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...