5

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?

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

As much as external links are useful for reference, please make sure to embed the answer into the SO post.
-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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.