【问题标题】:Iframe Auto resize not working in Firefox using javascriptiframe 自动调整大小在使用 javascript 的 Firefox 中不起作用
【发布时间】: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>

考虑我使用超链接&lt;a href="index2.htm"&gt;Redirect&lt;/a&gt;

如果我点击Redirect 超链接,它会重定向到index2.htm 文件,iframe 会根据内容自动调整大小。如果我返回(浏览器返回或返回按钮)到上一页(index.htm),iframe 自动调整大小仅在 firefox 中不起作用..它在 IE 中工作正常..

是否有任何解决方案可以在使用 javascript 或 jquery 的 firefox 中工作?

【问题讨论】:

  • $(window).on('resize',function(){...}); !!!
  • 欢迎 C-link..你已经回答了我的很多问题..你能解释一下这个 jquery 吗?怎么用?

标签: javascript jquery html iframe autoresize


【解决方案1】:

使用这个:onresize="autoResize('CHANGETHIS');"

<iframe src="index.htm" scrolling='no'  width="100%" height="100%" name="CHANGETHIS" id="CHANGETHIS" marginheight="0" frameborder="0" onload="autoResize('CHANGETHIS');" onresize="autoResize('CHANGETHIS');"></iframe>

【讨论】:

  • 我在javascript中提到的自动调整大小功能怎么样?我可以删除吗?
  • 不,那是你的功能,如果你使用 onresize inline js 然后复制我的答案是 如果你想在 js 文件中使用,那么在 on resize 函数中放置你的代码。
  • 无法得到你兄弟...:(
  • 我修复了它兄弟..iframe 的高度问题..一旦加载 html,我将其设置为 0px..现在它工作正常..感谢您的帮助..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-02-07
  • 1970-01-01
  • 1970-01-01
  • 2013-03-27
  • 2016-05-29
  • 2011-10-27
  • 2012-12-05
相关资源
最近更新 更多