I have this html page, with javascript code, but I can not get the code to open one of the cases 3 pages, the settimeout works, but to connect the random selected page work, I have enclosed the code cf. below, if I am some skilled javascript people who can tell what needs to be done to make it work I would be grateful.
the browser open this up http://localhost:62206/'sitelist[ran]'
my html and javascript code below here
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script language="Javascript">
var sitelist = new array;
sitelist[0] = "www.ford.com";
sitelist[1] = "www.bmw.com";
sitelist[2] = "www.mercedes.com";
var ran = Math.floor(Math.random() * sitelist.length);
</script>
</head>
<body onload="myFunction()">
<h1>Hello World!</h1>
<script>
function myFunction() {
setTimeout(function () { location.href = "'sitelist[ran]'" }, 7000);
}
</script>
</body>
</html>`
CodePudding user response:
It is Array()
not array
.
And you wrapped the sitelist[ran]
in "' '"
for some reason, remove that.
When you use quotes, you create a string, but I don't think that's what you want to do there.
CodePudding user response:
or you can just declare it as simple as that
var sitelist = [];