iframe根据内部内容动态改变高度宽度

2023-12-12

我的 iframe 内容如下所示,

    <iframe  frameborder="no" src="http:localhost/com" id="iframe">
     <div style="height:850px;width:700px;">div text </div>
   </iframe>

这显示了带有 hori 的 iframe。和垂直滚动,但不是内部内容的高度 850px。

如何根据内部内容的高度和宽度动态更改 iframe 高度。我在内容中使用jquery。

它的跨域 js 小部件,因此下面的大多数答案都会抛出权限被拒绝的错误

谢谢, 尼西什


Nithish,

如果您使用 jquery,那么您可以轻松找到(并设置)任何 div 的高度(在您的域中 - 而不是外部内容上),如下所示:

// get the height - in case we want to factor it into the equation below!!
var myDivHeight = $('iframe').css('height');

// set the height
var docHeight = $(document).css('height');
$('iframe').css('height', docHeight);

希望这可以帮助 ...

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iframe根据内部内容动态改变高度宽度 的相关文章

随机推荐