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

192
Views
How to architect a JS widget to be embedded in different websites

I know this is vague, but I want to create a JS widget that can be embedded into webpages and the user can interact with. Similar to what these guys do with their chatbot widget.

It looks like they use an iframe. If I want to package up some code and make it easy to embed into other websites, is there a benefit to using an iframe? Is it something to do with cookies tracking etc.?

Thanks

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

0

To build a JS widget, you have many alternatives, I will describe two of them below :

1- Using an iFrame : this approach is the easiest one to implement, the only cons is that your widget code won't be able to interact with the host's webpage content. And vice versa, your host web application code won't be able to interact with your iFrame content. To implement this approach, you will have to host your iFrame content and reference it in an iFrame tag inside your host application.

2- Making a HTML renderer module : this approach is the most customizable. How it works : You will have to make a JS script that renders your HTML content. Example : Imagine your host website's code is as follows :

   

     // widget.js
        const widgetContentEl = document.getElementById('widget-content');
        var myWidget = document.createElement('div');
        myWidget.innerHTML = '<h1> This is my widget</h1> <p> And this is a paragraph in my widget';
        widgetContentEl.appendChild(myWidget);
<!-- index.htm -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Example host</title>
  </head>
  <body>
  <div id="widget-content"></div>
    <script src="widget.js"></script>
  </body>
</html>

This way, you can customize the widget.js content to render your widget.

I hope my answer was helpful.

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!