Simply put, iframes are simple because they eliminate any potential conflicts with the client website. This is vital if you also do not manage the clientโs website so that you control the environment in which you insert your widget.
Otherwise, situations when you embed your widget code directly on the clientโs website (without using an iframe) can cause a conflict with the HTML, CSS or Javascript client. You can write your widget code so that it does not conflict, but as a rule, you cannot depend on the code for your web page. All that is required is something poorly written on your client site to cause problems with the built-in widgets. CSS is a simple example. Say your client had something stupid in the stylesheet, for example:
div { background-color: red; }
... if you did not specify a background property with a more specific selector for all divs used in your widget, now they are red.
I think the best way to make widgets is to provide your clients with a single external script link that passes the client ID to the script URL. Your script starts with document.write () - with Iframe - so you have future control over all aspects of your widget (including iframe) without any changes from your clients.
source share