设置兄弟iframe的高度
son1.html
<html>
<script>
function test()
{
alert(1);
alert(parent.document.body.scrollHeight);
alert(parent.tt2.document.body.scrollHeight);
parent.document.getElementById("tt2").height=800;
}
</script>
<body>
<h1 id="myH1">
<input type="button" onclick="test()"/>
</body>
</html>
son1.html
<html>
<body>
<h1 id="myH1">hello,son2 2 2 2 2 </h1>
</body>
</html>
father.html
<html>
<body>
<Iframe name="tt1" src="son1.html" id="tt1" width="250" height="200" scrolling="no" frameborder="1"
></iframe>
<Iframe name="tt2" src="son2.html" id="tt2" width="250" height="200" scrolling="no"
frameborder="1"></iframe>
<h1 id="myH2">hello,my wife</h1>
</body>
</html>
引用点别人的东西
/**
* iframe高度处理
* @author zxub 2006-09-29
*/
/**
* 设置iframe高度等于内部页面高度,用于内部页面
*/
function setParentHeight(_iframeId)
{
if (parent.setIFrameHeight) return;
if (window.addEventListener) //firefox
{
var _action=function()
{
var _iframe=parent.document.getElementById(_iframeId);
if (!_iframe) return;
_iframe.height=_iframe.contentDocument.body.offsetHeight+16;
}
window.addEventListener("load", _action, false);
}
else if (window.attachEvent) //IE
{
var _action=function()
{
if (!parent.document.getElementById(_iframeId)) return;
parent.document.getElementById(_iframeId).height=document.body.scrollHeight;
}
window.attachEvent("onload", _action);
}
}
/**
* 设置iframe高度等于内部页面高度,用于父级页面
*/
function setIFrameHeight(_iframeId)
{
if (window.addEventListener) //firefox
{
var _action=function()
{
var _iframe=document.getElementById(_iframeId);
if (!_iframe) return;
_iframe.height=_iframe.contentDocument.body.scrollHeight;
_iframe.onload=function()
{
this.height=this.contentDocument.body.offsetHeight+16;
}
}
window.addEventListener("load", _action, false);
}
else if (window.attachEvent) //IE
{
var _action=function()
{
if (!document.getElementById(_iframeId)) return;
document.getElementById(_iframeId).height=document.frames[_iframeId].document.body.scrollHeight;
document.getElementById(_iframeId).onreadystatechange=function()
{
if (this.readyState=="complete")
{
this.height=document.frames[_iframeId].document.body.scrollHeight;
}
}
}
window.attachEvent("onload", _action);
}
}
父子之间传值
一 父到子
直接访问dom对象就ok了
二 子到父
parent.
iframe 设置iframe高度
最新推荐文章于 2025-01-08 17:00:26 发布