【发布时间】:2013-12-26 08:20:23
【问题描述】:
我想知道是否有某种方法可以做到这一点,如果 iFrame 中有一堆内容,它只会调整文档的大小以使其适合。使 iFrame 内的所有内容变小。为了澄清我想调整内容的大小,而不是 iFrame 本身的大小。
任何想法我会如何做到这一点?
我已经尝试了一些东西,但到目前为止没有运气。
脚本:
<script type="text/javascript">
function autoResize(id){
var newheight;
var newwidth;
if(document.getElementById){
newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
}
document.getElementById(id).height= (newheight) + "px";
document.getElementById(id).width= (newwidth) + "px";
}
</script>
iFrame:
<iframe id="iframehtml" style="width:100%;height:100%;" onLoad="autoResize('iframe1');"></iframe>
顺便说一下,没有为 iFrame 设置 src 的原因是因为我在 JavaScript 中有它,所以当你点击一个按钮时,它会通过 jQuery 编辑 iFrame 的 html。
【问题讨论】:
标签: javascript jquery html iframe