samedi 27 novembre 2021

javascript should open a random page after 7 seconds, but how?

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>`




Aucun commentaire:

Enregistrer un commentaire