iframe自适应大小
在嵌套动态的iframe页面时,需要自动适应iframe页面大小,代码如下
js方法
代码
<script language="javascript">
<!--
function SetWinHeight(obj)
{
var win=obj;
if (document.getElementById)
{
if (win && !window.opera)
{
if (win.contentDocument && win.contentDocument.body.offsetHeight)
win.height = win.contentDocument.body.offsetHeight;
else if(win.Document && win.Document.body.scrollHeight)
win.height = win.Document.body.scrollHeight;
}
}
}
-->
</script>
<!--
function SetWinHeight(obj)
{
var win=obj;
if (document.getElementById)
{
if (win && !window.opera)
{
if (win.contentDocument && win.contentDocument.body.offsetHeight)
win.height = win.contentDocument.body.offsetHeight;
else if(win.Document && win.Document.body.scrollHeight)
win.height = win.Document.body.scrollHeight;
}
}
}
-->
</script>
iframe Onload方法注册如下
<iframe src="ms.html" class="msbox" name="tag" marginwidth=0 allowtransparency="true" marginheight=0 hspace=0 vspace=0
frameborder=0 scrolling="no" onload="SetWinHeight(this)"></iframe>