javascript - 为iframe计算网页的动态高度

标签 javascript jquery html css iframe

这是 index.html 代码..

<body><iframe name="sample" src="first.html" width="100%" height="100%" frameborder="0"  id="sample" /></body>

first.html 代码是...

<body>
<div style="width:100%; height: 1900px; background: yellow;"></div>
 <br>
 <a href="second.html">second</a>
</body>

second.html代码为

    <body><div style="width:100%; height: 1100px; background: blue;"></div>
<br>
<a href="first.html">first</a></body>

现在我想要的是让索引页面以全高呈现整个 first.html 和 second.html。不知何故,iframe 高度必须调整到它所持有的网页的相应高度。 如何做到这一点?

最佳答案

处理 iframe 尺寸可能有点麻烦。这不完全是答案,但希望它能为您指明正确的方向。

您是 iframe 的作者(或者您有权访问作者)吗?如果是这样的解决方案,如 this应该可以。

我也会给 this图书馆(或其 58 个 fork 之一)查看一些灵感。根据我的经验,post-message API在使用 iFrame 时很有用,上面的库是基于 iFrame 构建的。

希望对您有所帮助!

关于javascript - 为iframe计算网页的动态高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26603306/

相关文章:

javascript - 从 javascript 到片段着色器的单色

javascript - 从javascript调用actionscript 3函数,addCallback不起作用

javascript - 随机选择数组中的值,然后应用于 jQuery 函数

php - 使用 PHP 和 CURL 创建新的 etherpad

javascript - 框架不重新加载

javascript - 在 JSON 对象中发送 Uint8Array (BSON)

JQuery Select2 克隆

javascript - JQuery on-change 事件未调用

javascript - 尽管刷新,jQuery 格式仍不适用于 ajax 数据

javascript - 全页导航幻灯片淡入淡出问题