使用 iFrame Resizer 在一个页面上显示多个 iframe

Multiple iframes on the one page with iFrame Resizer

iFrame Resizer 的文档说:

When the resizer does not work using multiple IFrames on one page, make sure that each frame has an unique id or no ids at all.

我选择不为 iframe 提供 ID。我的代码如下所示。它有效,但我想确认我做的一切都是正确的。具体来说,我只调用 iFrameResize() 一次并且没有参数 - 可以吗?

<iframe src="https://example.com/frame1" scrolling="no"></iframe>
<iframe src="https://example.com/frame2" scrolling="no"></iframe>

<script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.5.15/iframeResizer.min.js"></script>
<script>iFrameResize()</script>

注意:@david_bradshaw,我决定不使用ids,因为那样的话不清楚如何调用iFrameResize()——我们需要为每个 iFrame 调用一次吗?请说清楚。 TIA

我建议输入 ID。

不确定这是否有帮助。

  • Requires: iframeResizer.contentWindow.min.js to be loaded into the target frame.

参考: cloudflare.com(2018 年 1 月 21 日)

例子

<style>iframe{width: 1px;min-width: 100%;}</style>
<iframe id="myIframe" src="http://anotherdomain.com/iframe.html" scrolling="no"></iframe>
<script>iFrameResize({log:true}, '#myIframe')</script>

参考: davidjbradshaw(2018 年 1 月 21 日)

注意: ID 用于发送到调整器方法