iFrame从帧内的动态内容调整大小

时间:2015-12-18 02:54:11

标签: javascript css iframe

我正在构建的网站上有一个iframe。问题是,我在框架内显示的其中一个页面有一些动态内容(单击时可以扩展和缩小高度),iframe是否有办法调整其内容的大小?

它会加载静态页面的大小,但是一旦点击并展开了页面上的项目,iframe就不会随之展开。

我现在只是基本的,这是我的<head>内容:

    <script language="javascript" type="text/javascript">
  function resizeIframe(obj) {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
  }
</script>

这是我的iframe:

<iframe src="index2.php" name="frame" frameborder="0" scrolling="no" onload="resizeIframe(this)" />

1 个答案:

答案 0 :(得分:0)

我认为你想做的事情是不可行的。至少不是100%。 您可以尝试在iFrame中检测单击,但不能在特定目标中检测。

这个答案(Detect Click into Iframe using JavaScript)涵盖了iFrame中的单击。

希望它可以帮到你!

相关问题