所属分类:HTML网页,JS语言与代码
转载自http://www.zhangxinxu.com/study/201012/iframe-height-auto#height=117
HTML代码:
[code]<iframe id="testIframe" frameborder="0" scrolling="no" src="http://www.zhangxinxu.com/study/201012/iframe-page-no-fresh.html" width="100%" height="120"></iframe>[/code]
JS代码:
[code]<script>
//高度自适应
var iframe = document.getElementById("testIframe");
var iframeHeight = function() {
var hash = window.location.hash.slice(1), h;
if (hash && /height=/.test(hash)) {
h = hash.replace("height=", "");
iframe.height = h;
}
setTimeout(iframeHeight, 200);
};
iframeHeight();
</script>[/code]
放在同一HTML页面即可。
HTML代码:
[code]<iframe id="testIframe" frameborder="0" scrolling="no" src="http://www.zhangxinxu.com/study/201012/iframe-page-no-fresh.html" width="100%" height="120"></iframe>[/code]
JS代码:
[code]<script>
//高度自适应
var iframe = document.getElementById("testIframe");
var iframeHeight = function() {
var hash = window.location.hash.slice(1), h;
if (hash && /height=/.test(hash)) {
h = hash.replace("height=", "");
iframe.height = h;
}
setTimeout(iframeHeight, 200);
};
iframeHeight();
</script>[/code]
放在同一HTML页面即可。