如何动态修复 Google 趋势图的高度问题。 例如,查看以下代码的输出。
<iframe width="600" height="320" src="http://www.google.com/trends/fetchComponent?hl=en-US&q=css-showcase&content=1&cid=TIMESERIES_GRAPH_0&export=5&w=600&h=320" style="border: none;"></iframe>
<hr>
first contents
<hr>
<iframe width="600" height="320" src="http://www.google.com/trends/fetchComponent?hl=en-US&q=html5&content=1&cid=TIMESERIES_GRAPH_0&export=5&w=600&h=320" style="border: none;"></iframe>
<hr>
second contents
在 jsFiddle 上:http://jsfiddle.net/yzw8Y/
最佳答案
我没有测试它,但这可以工作。
function autoResize(id)
{
var newheight;
newheight=document.getElementById(id).contentWindow.document.body.scrollHeight;
document.getElementById(id).height=newheight + "px";
}
<iframe id="frame1" onload="autoResize('frame1')" ... >
关于javascript - 动态更改 IFRAME 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16519164/