Embed widget : javascript generate iframe - Stack Overflow

I need to develop a widget for embedding my contents on 3rd party HTMLs.I searched several pages about

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=".html</iframe>
using javascript is giving 3rd party users a script tag, e.g. <script src=".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 = '.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?

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./widget.html</iframe>
using javascript is giving 3rd party users a script tag, e.g. <script src="https://sample./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./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?

Share asked Feb 23, 2019 at 17:35 jiro.kokubunjijiro.kokubunji 511 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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

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 pared to when we use script tag.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745069765a4609475.html

相关推荐

  • Embed widget : javascript generate iframe - Stack Overflow

    I need to develop a widget for embedding my contents on 3rd party HTMLs.I searched several pages about

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信