Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

265
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

or you can just declare it as simple as that

var sitelist = [];
about 4 years ago · Juan Pablo Isaza Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda