这是 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/