当前位置: 首页 > 图文教程 > 网页制作 > CSS样式表 > Iframe自适应其加载的内容高度

CSS样式表
web标准常见问题集合4
web标准常见问题集合5
我的一些关于web标准的思考笔记(一)
关于filter滤镜应用于图片的两种创意
Div+Css(+Js)菜单代码及制作工具
css写菜单:简洁注释版
标准布局应用:显示/隐藏侧边栏 [附详细注解]
小心:CSS代码书写顺序不同,导致显示效果不一样
解决鼠标在 flash 链接上不停闪动的问题(web页面中)
从gb到utf-8
html在线编辑器的更新[2006-05]
对hao123进行重构
韩国商业网站设计分析
模仿combox(select)控件,不用为美化select烦恼了。
【已解决】标签页刷新问题
以前写的两个CSS树形菜单
CSS样式表的背景渲染效率
第1天:选择什么样的DOCTYPE
第2天:什么是名字空间
第3天:定义语言编码

CSS样式表 中的 Iframe自适应其加载的内容高度


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 74 ::
收藏到网摘: n/a

<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='站长中国 http://www.zzcn.net/'>
<title>iframe自适应加载的页面高度</title>
</head>
<body>
<iframe src="child.htm"></iframe>
</body>
</html>
child.htm:
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<meta name='author' content='站长中国 http://www.zzcn.net/'>
<title>iframe 自适应其加载的网页(多浏览器兼容)</title>
<script language=javascript>
function iframeAutoFit()
{
try
{
if(window!=parent)
{
var a = parent.document.getElementsByTagName("IFRAME");
for(var i=0; i<a.length; i++) //author:meizz
{
if(a[i].contentWindow==window)
{
var h = document.body.scrollHeight;
if(document.all) {h += 4;}
if(window.opera) {h += 1;}
a[i].style.height = h;
}
}
}
}
catch (ex)
{
alert("脚本无法跨域操作!");
}
}
if(document.attachEvent) window.attachEvent("onload", iframeAutoFit);
else window.addEventListener('load', iframeAutoFit, false);
</script>
</head>
<body>
<div style="width: 200; height: 400; background-color: yellow">
iframe 自适应其加载的网页(多浏览器兼容)
</div>
</body>
</html>