Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!