访问iframe
程序员文章站
2022-04-05 08:07:01
...
document.getElementById('test').contentWindow.document.getElementById('test').style.color='red'
<iframe id="frame_content" src="iframe_b.html" scrolling="no" frameborder="0" onload="this.height=100"></iframe>
<script type="text/javascript">
function reinitIframe(){
var iframe = document.getElementById("frame_content");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}catch (ex){}
}
window.setInterval("reinitIframe()", 200);
</script>
IE中iframe的ID不要与函数的名称相同
上一篇: js打开新窗口的方法
下一篇: 请求的站点不可用或找不到