Html 用iFrame填充窗口而不显示滚动条?
如何使iframe填充窗口而不显示任何滚动条 这适用于IE6,如果可能,我希望它适用于所有浏览器:Html 用iFrame填充窗口而不显示滚动条?,html,css,iframe,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 resize
<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>
函数resizeIframe(){
变量高度=document.documentElement.clientHeight;
高度-=document.getElementById('frame').offsetTop;
//不知道如何动态地获取此信息
高度-=20;/*无论您将身体底部边距/填充设置为什么*/
document.getElementById('frame')。style.height=height+“px”;
};
document.getElementById('frame')。onload=resizeIframe;
window.onresize=调整框架大小;
您应该能够仅使用CSS来完成此操作,而不需要任何javascript。以下内容适用于我在IE6+、谷歌浏览器和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>
经过IE6+、Chrome、Safari和Firefox的测试,它工作正常,可以填满整个窗口。我在滚动条和无上下文菜单显示方面遇到了同样的问题,尽管所有这些元素都已禁用。在尝试解决这些问题几天后,我偶然发现了这篇文章,这有点帮助,但让我找到了一篇关于灵活网络播放器的文章,其中有三个代码示例。以下是链接: 如果您希望空白工作表从中工作,请使用索引文件,替换导出的.html文件(从Unity导出)中的现有代码,将“unityObject.EmbeddeUnity”链接替换为指向服务器上.html文件的自己的链接 要使用iframe add将播放机嵌入页面,请执行以下操作: 锁定并加载 希望这有帮助
^_^iframe无法填满窗口。它将位于左上角的0,0处,大小约为300x150px。少了什么?感觉它应该填满整个窗口。@Zolomon:我的代码在IE、Firefox和Chrome中运行良好。也许你可以复制我写的测试代码,并以此为基础构建你自己的代码?谢谢,你的例子很有用!我不知道我的是怎么了。
<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>