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

CSS样式表
第7天:CSS入门
第10天:自适应高度
VML的基本概念
Shape对象与VML坐标系
Line,Polyline(线)对象
Rect,RoundRect(矩形)对象
Group容器
ShapeType给VML制作模版
脚本动态生成VML
放大缩小VML
给VML增加事件
数据图表
文本修改留痕
VML应用实例大全
建立WEB两大经典!《VML极道教程》+FlashVml(闪耀之星)3.0中/英文版联合发布!
何为“VML”、VML的基底知识
VML网页文件的基本格式
vml简介
欢迎品尝用vml画的苹果~~
iframe 背景透明 实现方法

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 72 ::
收藏到网摘: 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>