2015-12-02 23 views
0

任务是重新调整嵌入式iFrame的大小,该主体将在不重新加载自身或父级的情况下主动更改其内容,因此几乎所有可用的答案都不起作用,因为他们建议主动更改其高度的重新调整iFrame

<iframe src="url" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize('iframe1');"></iframe> 

使用onLoad调用调整大小功能。

回答

0

为了解决我的父母页面上的问题,我有以下几点: 的Index.aspx

<div> 
<script> 
    function resizeIframe(height) { 
    document.getElementById('frameUpload').height = height; 
    } 
    </script> 
<iframe id="iframe" src="/child/page.aspx" marginheight="0" frameborder="0"></iframe> 

而且我page.aspx体内我:

<body onChange="CallThisToResize();"> 

然后在身体内我有以下的JavaScript:

<script type="text/javascript"> 
function CallThisToResize() { 
    var body = document.body, 
html = document.documentElement; 

    var height = Math.max(body.scrollHeight, body.offsetHeight, 
        html.clientHeight, html.scrollHeight, html.offsetHeight); 
    parent.resizeIframe(height); 
} 

它的作用是什么,每次身体的变化,它得到了新的高度,将其发送给家长,然后将iframe高度的尺寸重新调整相应。