根据动态内容调整iFrame大小

时间:2013-09-14 12:50:55

标签: javascript html iframe dynamic height

在内部内容发生变化后,有没有办法让iframe刷新它的高度?

示例:http://thc-racing.ucoz.com/index/forum/0-14

我正在使用easyXDM

网页代码:

<script type="text/javascript" src="http://thc-racing.ucoz.com/design/forum-external/xdm/easyXDM.js"></script>
<div id="page-body">
<!-- do not define an iframe, it will get generated for you in this container -->
</div>
<script type="text/javascript">
new easyXDM.Socket({
    remote: "http://thc-racing.forumotion.co.uk/",
    container: document.getElementById("page-body"),
    onMessage: function(message, origin){
        this.container.getElementsByTagName("iframe")[0].style.height = message + "px";
        this.container.getElementsByTagName("iframe")[0].style.width = "900px";
    }
});
</script>

iFramed页面:

<script type="text/javascript" src="http://thc-racing.ucoz.com/design/forum-external/xdm/easyXDM.js"></script>
<script type="text/javascript">
var socket = new easyXDM.Socket({
onReady:  function() {
// this is needed for setting height on initial load
socket.postMessage(document.body.scrollHeight)
},
onMessage: function(message, origin){
// this is called from consumer (maybe by a timer)
socket.postMessage(document.body.scrollHeight)
}
});
</script>

感谢。

0 个答案:

没有答案