日期:2014-05-16  浏览次数:20474 次

求助,有没有获取页面document或者body高度变化的事件
有个iframe欠套页面,iframe里面的有一个 <textarea   style= "overflow-y:visible "   />
目的是iframe里面的页面大小改变了,触发iframe的大小改变。有没有一个通用的捕捉页面大小改变的事件。最好是document或body的事件。


------解决方案--------------------
就是onload事件.
------解决方案--------------------
这里有段抄来的代码,希望对你有用.

function f_frameStyleResize(targObj){

var targWin = targObj.parent.document.all[targObj.name];
if(targWin != null) {
var HeightValue = targObj.document.body.scrollHeight
if(HeightValue < 400){HeightValue = 400}
targWin.style.pixelHeight = HeightValue;
}

}

function f_iframeResize(){

bLoadComplete = true; f_frameStyleResize(self);
}

var bLoadComplete = false;
window.onload = f_iframeResize;

这段代码的意思是根据iframe的高度,自动调整父窗口中iframe的高度,让iframe全显示出来.
------解决方案--------------------
onresize
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=utf-8 " />
<title> shawl.qiu template </title>
<style type= "text/css ">
/* <![CDATA[ */

/* ]]> */
</style>
<script type= "text/javascript ">
/* <![CDATA[*/
if (navigator.appName== "Microsoft Internet Explorer ")
{
//最大化窗口
self.moveTo(-5,-5)
self.resizeTo(screen.availWidth +8,screen.availHeight+8)
//这个脚本定义的宽度其实比原窗口还要大那么一点.
}
/*]]*/
</script>
</head>
<body>
<script type= "text/javascript ">
/* <![CDATA[*/
onresize =
function()
{
defaultStatus = fGetViewPortSize();
}
function fGetViewPortSize()
{// shawl.qiu code, return Array
var myWidth = 0, myHeight = 0;
if(typeof(window.innerWidth ) == 'number ' )
{//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
}
else if
(
document.documentElement &&
( document.documentElement.clientWidth || document.documentElement.clientHeight )
)
{//IE 6
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
}
else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
{ //IE 4
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
return [myWidth, myHeight];
} // end function fGetViewPortSize
/*]]*/
</script>
</body>
</html>

------解决方案--------------------
onload也要:
<body onresize= "alert( 'bodyResize: ' + this.scrollHeight) ">
---> > >
<body onresize= "alert( 'bodyResize: ' + this.scrollHeight) " onload= "alert( 'bodyResize: ' + this.scrollHeight) ">
------解决方案--------------------
body是没有onresize事件地...