2010-02-02 47 views
7

如何让我的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> 
+0

使用'框架集'。 ;) – graphicdivine 2010-02-02 15:54:43

回答

19

你应该只能够做到这一点使用CSS,而不需要任何的JavaScript。在IE6 +,谷歌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> 

你帧的利润率应该在theSiteToShow.html身体进行设置。

UPDATE
按照您的意见,我用下面的测试页:

<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> 

在IE6 +,Chrome浏览器,Safari和Firefox测试,它工作得很好,并充满整个窗口。

+0

iframe不会填满窗口。它将自己置于左上角的0,0处,大小约为300x150像素。少了什么东西?感觉它应该填满窗户。 – Zolomon 2010-02-02 13:08:29

+0

@Zolomon:我的代码适用于IE,Firefox和Chrome。也许你可以复制我编写的测试代码,并用它作为基础来构建自己的代码? – 2010-02-02 13:46:23

+0

谢谢你的例子!不知道我的错在哪里。 – Zolomon 2010-02-04 12:20:55

0

即使所有这些元素都被禁用,我也遇到了与滚动条相同的问题以及没有显示上下文菜单。在试图解决它们几天之后,我偶然发现了这篇文章,这有点帮助,但是让我在三个代码示例中找到了一篇关于灵活网页播放器的文章。我这里还有链接:

http://virtualplayground.d2.pl/?p=367#comment-224

Download package

使用索引文件,如果你想要一张白纸,从工作,在导出的.html文件替换现有的代码(从Unity出口),用您自己的链接替换位于服务器上的.html文件的'unityObject.embedUnity'链接。

要嵌入使用iframe附加在你的网页播放器:

装弹。

希望这会有所帮助。

^_^