我正在使用此脚本根据内容自动调整iframe的高度和宽度 .
<script language="JavaScript">
function autoResize(id){
var newheight;
var newwidth;
if(document.getElementById){
newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
}
document.getElementById(id).height= (newheight) + "px";
document.getElementById(id).width= (newwidth) + "px";
}
</script>
在Iframe onload中调用此函数..
<iframe src="index.htm" scrolling='no' width="100%" height="100%" name="CHANGETHIS" id="CHANGETHIS" marginheight="0" frameborder="0" onLoad="autoResize('CHANGETHIS');"></iframe>
考虑我正在使用超链接 <a href="index2.htm">Redirect</a>
如果我单击 Redirect
超链接,它将重定向到 index2.htm
文件,并根据内容自动调整iframe大小 . 如果我回去(浏览器后退或后退按钮)到上一页(index.htm),iframe自动调整大小只能在firefox中工作..它在IE中正常工作..
有没有任何解决方案可以使用javascript或jquery在firefox中工作?
1 回答
使用此:
onresize="autoResize('CHANGETHIS');"