本文へスキップ

아이프레임 리사이징

MintState 2008年11月10日 11:51 閲覧 13141

아이프레임 리사이징

본페이지

<div id="a_iframe" style="width:645px; table-layout:fixed;">
	<iframe id="iframeID" name="iframeID" src="Iframe.html" width="100%" height="0" frameborder="0" scrolling="no"></iframe>
</div>

해당 Iframe 페이지

<script language="JavaScript">
function autoResize() {
	try {
		resizeTo(document.body.scrollWidth, document.body.scrollHeight);
	}
	catch(e) {
		window.setTimeout("autoResize()", 1000);
	}
}
</script>

<script language="JavaScript" for="window" event="onload">
window.setTimeout("autoResize()", 500);
window.setTimeout("autoResize()", 1000);
</script>

파이어폭스(firefox) 적용 소스

<SCRIPT LANGUAGE="JavaScript">
function resizeFrame() {
var min_h = 600;
	var oIFrame = document.getElementById("content_");
        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);
		}
		if (frmHeight < min_h) frmHeight = min_h;
		oIFrame.style.height = frmHeight;
	} catch (e) { }
}
</script>
--------------------------------------------------------------------
<iframe id="content_" name="content_" src="" width="100%" height="600" frameborder="0" scrolling="auto" onload="resizeFrame()"></iframe>

====================================================
네이트 클럽에서 사용하는 소스

<SCRIPT LANGUAGE="JavaScript">
// iframe resize Function
function reSizeFrm()
{
        var objTotal = document.body;
	var objBody	    =	ifrm.document.body;
	var objFrame	=	document.all["ifrm"];

	if ( objBody == null )
		setTimeout("reSizeFrm();",1000);
	else
	 	objFrame.style.height = objBody.scrollHeight + (objBody.offsetHeight - objBody.clientHeight)+182;
	objFrame.style.width = '100%';
}
// iframe initialize Function
function frame_init()
{
	parent.reSizeFrm();
	parent.scrollTo(1,1);
}

setTimeout("parent.resizeFrame();",500);
</script>
共有 X Facebook LINE QR コード

コメント 0 件

最初のコメントを書いてみましょう。