Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

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

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

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.

about 4 years ago · Juan Pablo Isaza Denunciar

0

or you can just declare it as simple as that

var sitelist = [];
about 4 years ago · Juan Pablo Isaza Denunciar

0

hope you doing well, here are some minor changes to your code to solve your problems, i'll answer to questions if necessary.

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script language="Javascript">
        var sitelist = [];
        sitelist[0] = "https://www.ford.com/";
        sitelist[1] = "https://www.bmw.com/fr/index.html";
        sitelist[2] = "https://www.mercedes-benz.com/en/";
 
        var ran = Math.floor(Math.random() * sitelist.length);
    </script>

   
</head>
<body onload="myFunction()">

    <h1>Hello World!</h1>

    <script>
        function myFunction() {
            setTimeout(function () { window.location.href = sitelist[ran] }, 7000);
        }
    </script>

</body>
</html>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda