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

104
Vistas
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 Respuestas
Responde la pregunta

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