调整iframe大小以适应多个页面上的内容

时间:2022-12-03 15:37:08

Could somebody please show me how to fit an iframe to the content within? I have this because I am using one iframe on my website that when a link is clicked displays different pages and I would love for the iframe to fit to the content within as at the moment the iframe is too long for some page's content but too short for other page's content and it cuts the page off.

有人可以告诉我如何在内容中放入iframe吗?我有这个,因为我在我的网站上使用一个iframe,当点击一个链接显示不同的页面,我希望iframe适合内容,因为iframe对于某些页面的内容来说太长,但是太短对于其他页面的内容,它会关闭页面。

I do not really have much code to show which is relevant or that will be any help, however in line with the rules on Stack below is the code that I have so far.

我真的没有太多的代码来显示哪些是相关的或哪些将是任何帮助,但是根据下面的Stack规则是我到目前为止的代码。

I have seen some questions on here regarding the same thing but none that I really understand.

我在这里看到了一些关于同样事情的问题但没有我真正理解的问题。

<iframe id="preview-frame" src="http://airforceadvice.com/PCS" name="preview-frame" frameborder="0" scrolling="no">
      </iframe>

1 个解决方案

#1


0  

Add this to your head section

将此添加到您的头部

<script language="javascript" type="text/javascript">
    function resizeIframe(obj) {
        obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
    }
</script>

And change your iframe to this:

并将您的iframe更改为:

<iframe name="Stack" src="http://*.com/" frameborder="0" scrolling="no" id="iframe" onload='javascript:resizeIframe(this);' />

Is this what you're looking for?

这是你在找什么?

#1


0  

Add this to your head section

将此添加到您的头部

<script language="javascript" type="text/javascript">
    function resizeIframe(obj) {
        obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
    }
</script>

And change your iframe to this:

并将您的iframe更改为:

<iframe name="Stack" src="http://*.com/" frameborder="0" scrolling="no" id="iframe" onload='javascript:resizeIframe(this);' />

Is this what you're looking for?

这是你在找什么?