본문 바로가기

JAVASCRIPT

아이프레임(iframe) 자동 크기조절(리사이즈)


iframe 창 크기 내용에따라 변하게 하기


<script language="javascript">

function ifrmReSize(){
  var oIFrame = document.getElementById("frmContent"); 
  try { 
   var oDoc = oIFrame.contentDocument || oIFrame.contentWindow.document; 
   if (/MSIE/.test(navigator.userAgent)) { 
    var frmHeight = oDoc.body.scrollHeight; 
   } else { 
    var s = oDoc.body.appendChild(document.createElement('DIV')) 
    s.style.clear = 'both'; 
    var frmHeight = s.offsetTop; 
    s.parentNode.removeChild(s); 
   } 
    document.getElementById("frmContent").height = frmHeight; 
  } catch (e) { } 
 }

</script>




<iframe name="bbsList" id="frmContent" src='/cop/bbs/selectBoardList.do?bbsId=BBSMSTR_000000000139' frameborder="0" scrolling="no" width="100%" height="100%" onload="ifrmReSize()" title="새소식"></iframe>


---------------------------------------------------------------------------------


<script language="javascript">

<!--

function resize_frame(obj){  
 var obj_document = obj.contentWindow.document; 
 if(obj_document.height){
  obj.style.height = obj_document.height;
  obj.style.width = obj_document.width; 
 } else {
  obj.style.height = obj_document.body.scrollHeight;
  obj.style.width = obj_document.body.scrollWidth; 
 }
}

//-->

</script>

 

<iframe src="링크주소" width='100%' height='100%' marginwidth='0' marginheight='0' frameborder='no' scrolling='no' onload='resize_frame(this)' name="iframe_list" id="iframe_list" target="_self"></iframe>

 

------------------------------------------------------------------ 

<script>

function resizeFrame(iframeObj){
    var innerBody = iframeObj.contentWindow.document.body;
    var innerHeight = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight);
    var innerWidth = innerBody.scrollWidth + (innerBody.offsetWidth - innerBody.clientWidth);
    iframeObj.style.height = innerHeight;
    iframeObj.style.width = innerWidth;
}

</script>

 

<iframe src="filename.html" name="iframe1" frameborder="0" scrolling="no" onload="resizeFrame(this)"></iframe>