ifram 높이 자동 조절 하는 스크립트

Posted by Albert 4790Day 20Hour 28Sec ago [2012-03-08]

// 우선 인클루드된 js파일에 해당 함수를 넣는다

// 자동적으로 iframe 높이 조절

function doIframe(){

    o = document.getElementsByTagName('iframe');


    for(var i=0;i<o.length;i++){  

        if (/\bautoHeight\b/.test(o[i].className)){

            setHeight(o[i]);

            addEvent(o[i],'load', doIframe);

        }

    }

}


function setHeight(e){

    if(e.contentDocument){

        e.height = e.contentDocument.body.offsetHeight + 35; //높이 조절

    } else {

        e.height = e.contentWindow.document.body.scrollHeight;

    }

}


function addEvent(obj, evType, fn){

    if(obj.addEventListener)

    {

    obj.addEventListener(evType, fn,false);

    return true;

    } else if (obj.attachEvent){

    var r = obj.attachEvent("on"+evType, fn);

    return r;

    } else {

    return false;

    }

}


if (document.getElementById && document.createTextNode){

 addEvent(window,'load', doIframe); 

==============================================================

iframe을 삽일할 위치에 아래 코드를 넣는다

==============================================================

<iframe id="guideIndutyIframe" src="http://cemware.nowdesign.kr/ad/cms/cms.php?mid=tutorial" title="게시판" class="autoHeight" name="guideIndutyIframe" scrolling="no" frameborder='0' marginwidth='0'marginheight='0' width="100%" ></iframe>




LIST

Copyright © 2014 visionboy.me All Right Reserved.