简体   繁体   English

如何动态调整Shindig小工具的iframe高度

[英]How to dynamically adjust iframe height of a Shindig Gadget

I want to dynamically adjust the height of an iframe of a Shindig Gadget depending on content inside of it. 我想根据其中的内容动态调整Shindig小工具的iframe的高度。 After some research I found out that it is required such iframe src to have <!DOCTYPE ...> declared to get the height of the content inside iframe using the following: 经过研究后,我发现需要这样的iframe src声明<!DOCTYPE ...>才能使用以下内容获取iframe中内容的高度:

document.getElementById("iframe").contentWindow.document.body.scrollHeight

But it is impossible to define a doctype inside <![CDATA[ of a Shinding module. 但是,不可能在Shinding模块的<![CDATA[内部定义doctype。 What's the best way to achieve this? 实现此目标的最佳方法是什么?

You should use the adjustHeight API in order to do this. 您应该使用adjustHeight API来执行此操作。 Calling the API without any arguments will adjust the iFrames height to fit it's contents. 调用不带任何参数的API会调整iFrame的高度以适合其内容。 http://opensocial-resources.googlecode.com/svn/spec/trunk/Core-Gadget.xml#gadgets.window.adjustHeight http://opensocial-resources.googlecode.com/svn/spec/trunk/Core-Gadget.xml#gadgets.window.adjustHeight

Try this 尝试这个

Here is an working example click here 这是一个工作示例, 请单击此处

<script type="text/javascript">
 function resizeIframe(obj)
  {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
 }
</script>

<iframe src="http://www.yahoo.com" onload='javascript:resizeIframe(this);'></iframe>

</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM