【发布时间】:2015-12-18 00:10:20
【问题描述】:
我正在尝试根据内容(网页)的高度和宽度调整 iframe 的大小。我使用了在堆栈的其他答案中找到的代码。对于新宽度的设置,似乎可行,但我无法使该高度起作用,我不知道为什么。
您可以在此处查看和编辑我的示例:http://jsfiddle.net/dzorz/pvtr3/
这是我的 HTML:
<iframe id="finance-iframe" class="finance-iframe" src="http://wordpress.org" width="100%" height="300px" marginheight="0" frameborder="0" onLoad="autoResize('finance-iframe');"></iframe>
和javascript:
function autoResize("finance-iframe"){
var newheight;
var newwidth;
if(document.getElementById){
newheight=document.getElementById("finance-iframe").contentWindow.document.body.scrollHeight;
newwidth=document.getElementById("finance-iframe").contentWindow.document.body.scrollWidth;
}
document.getElementById("finance-iframe").height= (newheight) + "px";
document.getElementById("finance-iframe").width= (newwidth) + "px";
}
我做错了什么?
【问题讨论】:
-
解决方案已经在这里找到了:stackoverflow.com/questions/9975810/…
标签: javascript html css iframe