iframe 是一个糟糕的主意吗?

2022-01-18 00:00:00 widget iframe javascript

我正在构建一个小部件,并且一直在使用 iframe 来呈现其中的内容.在某个时候,我可能会开始提供第三方 HTML 和 JS,所以我认为 iframe 会是一个好主意.

I'm building a widget, and I've been using iframes to present content within it. At some point, I might start serving third party HTML and JS, so I thought iframes would be a good idea.

它确实使小部件 javascript 稍微复杂了一点,我担心这可能不是最好的实现.

It does make the widget javascript a little more complicated, and I'm concerned that this might not be the best implementation.

你有什么建议吗?了解其他人对 iframe 的看法会很有帮助.

Do you have any advice? It would be a huge help to hear what other people think about iframes.

推荐答案

不,iframe 没有问题.如果您要开始提供第三方内容,iframe 可能是一个更好的主意.

No, nothing wrong with iframes. Iframes are probably a better idea if you're going to start serving third party content.

即将发布的 HTML5 规范还计划在 iframe 中针对此类情况构建更多安全功能,因此我认为现在也使用它们是一种好习惯.

The upcoming HTML5 spec also plans to build more security features into iframes for situations like this, so I would consider it good practice to use them now also.

相关文章