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

99
Views
Wait sometime before loading a widget onto a page

I'm new to programming and the following code I got through an open source project.

I'm loading a widget on a website. So instead of immediately loading the widget, I want it to take 10 secs before showing the widget.

This is how I'm loading the widget.

Entire code below............

switch (methodName) {
            case 'init':

                const loadedObject = Object.assign(defaultConfig, item[1]);
           
                // the actual rendering of the widget
    
                const wrappingElement =
                    loadedObject.element ?? win.document.body;
                targetElement = wrappingElement.appendChild(
                    win.document.createElement('div')
                );
                targetElement.setAttribute('id', `widget-${instanceName}`);
                render(targetElement, loadedObject);

                // store indication that widget instance was initialized
                win[`loaded-${instanceName}`] = true;
                break;
    
            default:
                console.warn(`Unsupported method [${methodName}]`, item[1]);
        }

    }

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you should use the setTimeout function as such:

switch (methodName) {
  case 'init':

    const loadedObject = Object.assign(defaultConfig, item[1]);       
    setTimeout(function(){
    
      // the actual rendering of the widget
      const wrappingElement =
          loadedObject.element ?? win.document.body;
      targetElement = wrappingElement.appendChild(
          win.document.createElement('div')
      );
      targetElement.setAttribute('id', `widget-${instanceName}`);
      render(targetElement, loadedObject);

      // store indication that widget instance was initialized
      win[`loaded-${instanceName}`] = true;

    }, 10000);

  break;
    
  default:
    console.warn(`Unsupported method [${methodName}]`, item[1]);
    }

}

as shown in this answer here

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!