我需要开发一个小部件,用于嵌入我的内容到第三方HTML中。
我搜索了几个关于这个主题的网页,并了解了使用iframe和javascript的优缺点,但仍然有一个问题。
我的意思是:
使用iframe会提供给第三方用户一个iframe标记,例如
使用javascript会给第三方用户提供一个脚本标记,例如
我搜索了几个关于这个主题的网页,并了解了使用iframe和javascript的优缺点,但仍然有一个问题。
我的意思是:
使用iframe会提供给第三方用户一个iframe标记,例如
<iframe src="https://sample.com/widget.html</iframe>
使用javascript会给第三方用户提供一个脚本标记,例如
<script src="https://sample.com/widget.js</script>
有一个页面介绍了如何使用Js,但他们的Js代码只是生成一个iframe并将其插入到父节点中,并将内容设置为iframe。
例如: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();
我想知道使用iframe和由Js生成并插入的iframe之间的区别是什么?
我的理解是,如果我想改变iframe的行为/外观,通过Js生成的iframe更好。但是,如果Js代码只是插入iframe,则几乎具有相同的行为。这正确吗?