Reputation: 51
I need to develop a widget for embedding my contents on 3rd party HTMLs.
I searched several pages about this topic, and understood pros/cons of using iframe and javascript but still remain one question.
I mean:
using iframe is giving 3rd party users a iframe tag, e.g. <iframe src="https://sample.com/widget.html</iframe>
using javascript is giving 3rd party users a script tag, e.g. <script src="https://sample.com/widget.js</script>
A page explains about using Js, but their Js code just generates iframe and insert it into parent's node and set contents to iframe. e.g.
var iframe = document.createElement('iframe');
iframe.src = 'https://sample.com/widget.html
// insert iframe into parent node
// or set content into document
var doc = iframe.contentWindow.document;
doc.open();
doc.write('content');
doc.close();
My question is how differences between just using iframe and using iframe that Js generated and inserted?
My understanding is that iframe via Js is better if I want to change iframe's behavior/appearance. But these are almost same behavior if Js code just inserting iframe. Is it correct?
Upvotes: 5
Views: 6060
Reputation: 305
have you explore Zoid? It is a boilerplate to help you design an embeddable widget script with security as its main feature. Check this article
Upvotes: 4
Reputation: 1
Inserting the iframe directly as embed code is similar to inserting the js code to load and render iframe. There is no difference. But there are differences when we use our embed as iframe tag as compared to when we use script tag.
Upvotes: -1