我正在尝试使 iframe 高度自动(100%),因此搜索了很多示例。
但问题是......它在 IE 中不能很好地工作,只能在 Chrome 中工作。
<div class="stockIframe ">
<iframe src="http://google.com" onload="autoResize(this)" height="100%" width="100%"></iframe>
</div>
html,body { height: 100% }
.stockIframe { width:100%; height:100%; }
.stockIframe iframe { width:100%; height:100%; border:0;overflow:hidden }
<script>
function autoResize(i)
{
var iframeHeight=
(i).contentWindow.document.body.scrollHeight;
(i).height=iframeHeight+20;
}
</script>
谁知道怎么修它 ?
我看你的代码没有问题,但不要忘记style
tag
我在 IE 11 上测试过,它可以工作。
<div class="stockIframe ">
<iframe src="http://google.com" onload="autoResize(this)" height="100%" width="100"></iframe>
</div>
<style>
html,body { height: 100% }
.stockIframe { width:100%; height:100%; }
.stockIframe iframe { width:100%; height:100%; border:0;overflow:hidden }
</style>
<script>
function autoResize(i) {
var iframeHeight=
(i).contentWindow.document.body.scrollHeight;
(i).height=iframeHeight+20;
}
</script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)