2009년 12월 10일 목요일

자바스크립트로 iFrame의 높이를 100%로 하기

자바스크립트로 iFrame의 높이를 100%로 하기
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD>
<TITLE>Iframe with 100% height</TITLE>
<script language="JavaScript">
<!--
function resize_iframe() {

document.getElementById("info").innerHTML='iframe offsetTop: <b> '+document.getElementById("glu").offsetTop+"</b> body.offsetHeight:<b>"+document.body.offsetHeight+"</b>";//display some information on the screen

var height=window.innerWidth;//Firefox

if (document.body.clientHeight) {

height=document.body.clientHeight;//IE
}
//resize the iframe according to the size of the window
document.getElementById("glu").style.height=parseInt(height-document.getElementById("glu").offsetTop-8)+"px";
//document.getElementById("glu").height=document.body.offsetHeight-document.getElementById("glu").offsetTop-26;
}

window.onresize=resize_iframe; //instead of using this you can use: <BODY onresize="resize_iframe()">
//-->
</script>
</HEAD>
<body onLoad="resize_iframe();">
<br>
<span id=info><!-- This is just for displaying some information --></span>
<br><br>
<iframe id='glu' width=100% onload='resize_iframe()'></iframe>
</BODY>
</HTML>

댓글 없음: