【发布时间】:2014-06-01 05:26:59
【问题描述】:
我正在使用此脚本根据内容自动调整 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 中工作?
【问题讨论】:
-
$(window).on('resize',function(){...}); !!!
-
欢迎 C-link..你已经回答了我的很多问题..你能解释一下这个 jquery 吗?怎么用?
标签: javascript jquery html iframe autoresize