在表格里放了一个自适应高度的iframe,这个自适应高度的iframe单独运行的时候都正常,放到另外一个网页的表格里之后却不能正常自适应高度了。
--------------------------------------------------------------------------
自适应高度的iframe页面代码如下:
<script type="text/javascript">// < ![CDATA[
// < ![CDATA[
// < ![CDATA[
function setIframe(){
var iframe = document.getElementById("iframeB");
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = bHeight>dHeight?bHeight:dHeight;
iframe.height = height;
}
// ]]></script>
<iframe width="100%" name="iframeB" id="iframeB" src="test.asp.htm" marginwidth="0" marginheight="0" frameborder="0" onload="Javascript:setIframe()" scrolling="no"></iframe>
-------------------------------------------------------------------------------
--------------------------------------------------------------------------
自适应高度的iframe页面代码如下:
<script type="text/javascript">// < ![CDATA[
// < ![CDATA[
// < ![CDATA[
function setIframe(){
var iframe = document.getElementById("iframeB");
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = bHeight>dHeight?bHeight:dHeight;
iframe.height = height;
}
// ]]></script>
<iframe width="100%" name="iframeB" id="iframeB" src="test.asp.htm" marginwidth="0" marginheight="0" frameborder="0" onload="Javascript:setIframe()" scrolling="no"></iframe>
-------------------------------------------------------------------------------
function setIframe(){
var iframe = document.getElementById("iframeB");
var doc=iframe.contentDocument||iframe.contentWindow.document;//浏览器兼容
var docE=document.compatMode=="CSS1Compat"?document.documentElement:document.body;//DOCTYPE 兼容
/*
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
*/
var sH = docE.scrollHeight;
iframe.style.height = sH +'px';
}
</script>