iframe根据内容自动伸缩
来源:互联网 发布:阿里云的dns是多少 编辑:程序博客网 时间:2024/05/02 02:12
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;
}
}
}
{
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>
<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>
<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>
</html>
文件test.htm
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<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>
<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根据内容自动调整长度.
- 根据内容自动调整IFrame高度
- 使IFrame根据内容自动调整大小
- iframe 的高度根据内容自动调整
- 根据内容自动调整iframe框架高度
- 让iframe根据内容自动调整高度~~~
- 根据内容自动调整IFrame高度
- iframe自动根据内容调整大小
- 可根据内容多少自动伸缩的textarea
- wrap_content 根据内容(content)伸缩
- IFrame根据内容自动适应高宽(同域)
- jquery控制iframe根据内容高度自动调整问题。
- 我是设计师 别TMD碰我的显示器
- [翻译] Effective C++, 3rd Edition, Item 47: 为类型信息使用 traits classes(特征类)(上)
- 抛弃ubuntu的eclipse
- 我选择的linux发行版
- 接近尾声咯
- iframe根据内容自动伸缩
- 传统过年习俗遭遇网络冲击
- 线程数据库编程
- 王者归来
- Pascal语法的技巧
- 爱的几种写法
- function gb2utf8(data)
- 出门没看黄历
- 人生哲理的几个幽默