iframe根据内容自动伸缩
2006-02-07 08:30
288 查看
iframe,尤其是不带边框的iframe因为能和网页无缝的结合从而不刷新页面的情况下更新页面的部分数据成为可能,可是iframe的大小却不像层那样可以“伸缩自如”,所以带来了使用上的麻烦,给iframe设置高度的时候多了也不好,少了更是不行。
======================方法1======================
function SetCwinHeight()
{
var cwin=document.getElementById("cwin");
if (document.getElementById)
{
if (cwin && !window.opera)
{
if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
cwin.height = cwin.contentDocument.body.offsetHeight;
else if(cwin.Document && cwin.Document.body.scrollHeight)
cwin.height = cwin.Document.body.scrollHeight;
}
}
}
最后,加入iframe,不能丢掉onload属性,当然了,id也必须也函数中的cwin匹配
<iframe width="778" align="center" height="200" id="cwin" name="cwin" onload="Javascript:SetCwinHeight()" frameborder="0" scrolling="no"></iframe>
====================方法2======================
文件temp.htm
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body onLoad=parent.setSize(getSize())>
<table width="100" height="660" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFCC66">
<tr>
<td> </td>
</tr>
</table>
<div id=PageEnd style="position:relative"></div>
<script language="JavaScript">
function getSize(){
return document.getElementById("PageEnd").offsetTop
}
</script>
</body>
</html>
文件test.htm
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<script language="JavaScript" type="text/JavaScript">
function setSize(theHeight){
document.all.ifrm.height=theHeight+12;
}
</script>
<iframe id=ifrm width="100%" height="0px" scrolling="no" src="temp.htm"></iframe>
</body>
</html>
======================方法1======================
function SetCwinHeight()
{
var cwin=document.getElementById("cwin");
if (document.getElementById)
{
if (cwin && !window.opera)
{
if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
cwin.height = cwin.contentDocument.body.offsetHeight;
else if(cwin.Document && cwin.Document.body.scrollHeight)
cwin.height = cwin.Document.body.scrollHeight;
}
}
}
最后,加入iframe,不能丢掉onload属性,当然了,id也必须也函数中的cwin匹配
<iframe width="778" align="center" height="200" id="cwin" name="cwin" onload="Javascript:SetCwinHeight()" frameborder="0" scrolling="no"></iframe>
====================方法2======================
文件temp.htm
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body onLoad=parent.setSize(getSize())>
<table width="100" height="660" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFCC66">
<tr>
<td> </td>
</tr>
</table>
<div id=PageEnd style="position:relative"></div>
<script language="JavaScript">
function getSize(){
return document.getElementById("PageEnd").offsetTop
}
</script>
</body>
</html>
文件test.htm
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<script language="JavaScript" type="text/JavaScript">
function setSize(theHeight){
document.all.ifrm.height=theHeight+12;
}
</script>
<iframe id=ifrm width="100%" height="0px" scrolling="no" src="temp.htm"></iframe>
</body>
</html>
相关文章推荐
- iframe根据内容自动伸缩
- iframe根据内容自动伸缩
- iframe自动根据内容调整大小
- iframe 自适应高度,更改内容时iframe高度怎么根据新的内容高度自动改变
- IFrame根据内容自动适应高宽(同域)
- iframe根据内容自动增长 zz (转载)
- jquery控制iframe根据内容高度自动调整问题。
- CSS布局 — 根据内容是否自动伸缩展示区域的那些元素
- iframe根据内容自动调整长度.
- 根据内容自动调整IFrame高度
- 根据内容自动调整IFrame高度
- 转载:iframe根据内容自动增长
- iframe根据内容自动调整高度,在ie,firfox可行,opera不行
- 根据内容自动调整iframe框架高度
- iframe 的高度根据内容自动调整
- 可根据内容多少自动伸缩的textarea
- 让iframe根据内容自动调整高度~~~
- AJAX基本应用之:根据输入内容自动填充下拉框。(ASP.NET版)[转]
- 让iframe框架网页在任何浏览器下自动伸缩
- 控制iframe的高度随内容的多而自动增长