[자바스크립트] iframe height 안에 내용 사이즈에 맞게 사용하기 (100% 사용하기)

류명운

·

2015. 12. 1. 22:42

반응형

[자바스크립트] iframe height 안에 내용 사이즈에 맞게 사용하기 (100% 사용하기)


사용 방법 1) 스크립트

<script language="JavaScript">
        function autoResize(obj){
            var newheight;
            var newwidth;

            if(obj.contentDocument){
                    newheight = obj.contentDocument.documentElement.scrollHeight+30;
                    newwidth = obj.contentDocument.documentElement.scrollWidth+30;
            } else {
                    newheight=obj.contentWindow.document.body.scrollHeight+30;
                newwidth=obj.contentWindow.document.body.scrollWidth+30;
            }

            obj.height= newheight + "px";
            obj.width= newwidth + "px";
        }
</script>



사용 방법 2) 바디

<iframe src="test.html" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize(this);" />


반응형