0

我想知道一个快速的 javascript 解决方案,可以根据其中的内容使 iframe 缩小/增大大小,这样就不需要滚动条了。

框架源会根据用户的输入进行更改,我希望 iframe 以此为基础调整其大小。

我拥有的 iframe 代码是:

<iframe id="edit_add_configuration" src="<?php echo site_url();?>">
        browser does not support this
</iframe>
4

1 回答 1

2

获取高度和宽度。

var height = document.getElementById("edit_add_configuration").contentWindow.document.body.scrollHeight;
var width = document.getElementById("edit_add_configuration").contentWindow.document.body.scrollWidth;

调整 iframe 的大小。

document.getElementById("edit_add_configuration").style.height=height+"px";
document.getElementById("edit_add_configuration").style.width=width+"px";
于 2012-05-24T04:41:32.160 回答