用iFrame填充窗口而不显示滚动条?

Zol*_*mon 9 html css iframe

如何让我的iframe填充窗口而不显示任何滚动条?

这适用于IE6,如果可能的话,我想让它适用于所有浏览器:

<iframe name=iframe1 src="theSiteToShow.html"  width="100%" height="100%" frameborder="0" marginheight="10" marginwidth="10"></iframe>
<script type="text/javascript">
function resizeIframe() {
    var height = document.documentElement.clientHeight;
    height -= document.getElementById('frame').offsetTop;

    // not sure how to get this dynamically
    height -= 20; /* whatever you set your body bottom margin/padding to be */

    document.getElementById('frame').style.height = height +"px";

};
document.getElementById('frame').onload = resizeIframe;
window.onresize = resizeIframe;
</script>
Run Code Online (Sandbox Code Playgroud)

And*_*y E 21

您应该只能使用CSS执行此操作,而无需使用javascript.以下适用于IE6 +,Google Chrome和Safari:

<style type="text/css">
body {
   margin: 0;
   overflow: hidden;
}
#iframe1 {
    position:absolute;
    left: 0px;
    width: 100%;
    top: 0px;
    height: 100%;
}
</style>

<iframe id="iframe1" name="iframe1" frameborder="0"  
     src="theSiteToShow.html"></iframe>  
Run Code Online (Sandbox Code Playgroud)

你的帧边距应该设置在正文中theSiteToShow.html.

更新
在您发表评论后,我使用以下内容作为测试页面:

<html> 
<head>
<style type="text/css">
body {
   margin: 0;
   overflow: hidden;
}
#iframe1 {
    position:absolute;
    left: 0px;
    width: 100%;
    top: 0px;
    height: 100%;
}
</style>
</head> 
<body> 
<iframe id="iframe1" src="http://stackoverflow.com" frameborder="0"></iframe>
</body> 
</html>
Run Code Online (Sandbox Code Playgroud)

经过IE6 +,Chrome,Safari和Firefox的测试,它可以很好地工作并填充整个窗口.