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

105
Visualizações
How do I add a delay to this script?

I have this simple script that applies a chat widget to the website. How can I delay this script from running for about 4 seconds?Here is a screenshot of the script

I tried looking up different solutions but nothing seemed to be the same circumstances.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

https://developer.mozilla.org/en-US/docs/Web/API/setTimeout

Wrap the entire script inside a named function block and call that from a setTimeout function:

(run the snippet and wait 4 seconds to see console message)

setTimeout(scriptCode, 4000);

function scriptCode (){
// place all script code here;
console.log("done");
} // end script

If you must reference the script from a named url, you can assemble a script tag in js and append it to the page after four seconds. Like this:


    setTimeout(scriptCode, 4000);

    function scriptCode (){

    const scriptElement=document.document.createElement('script');
    scriptElement.setAttribute("src", "http://scriptAddress.com");
    scriptElement.setAttribute("async", "");
    document.body.appendChild(scriptElement);

    } // end script

The script tag will be added to the DOM after 4 seconds and will load and execute as normal

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