0

如何动态解决谷歌趋势图表的高度问题。例如,查看以下代码的输出。

<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/

4

2 回答 2

1

我没有测试它,但这可以工作。

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')" ... >
于 2013-05-13T10:06:07.333 回答
-2

为 iframe 设置 id

并在 jquery 中设置高度

$('#idval').css('height','800px');

于 2013-05-13T09:53:12.483 回答