我被要求根据内容调整 iframe 的大小。经过长时间的搜索,我终于让它根据需要工作,但它只适用于 Firefox。我需要它至少在 chrome、ff 和 ie 上工作。这是脚本
<script language="JavaScript">
<!--
function autoResize(id){
var newheight;
if(document.getElementById){
newheight=document.getElementById(id).contentWindow.document.body.scrollHeight; //ff
newheight=document.getElementById(id).contentDocument.body.offsetHeight; //chrome
newheight=document.getElementById(id).contentDocument.documentElement.scrollHeight;
}
document.getElementById(id).height= (newheight) + "px";
}
//-->
</script>
和 iframe 代码
<iframe name="result" id="iframe" seamless src="action/search.php" width="100%" onLoad="autoResize('iframe');" marginwidth=0 marginheight=0 frameborder=0 scrolling="no" style="border:0; overflow:hidden">
</iframe>
任何建议表示赞赏。