[Script] Iframe 크기 내용에 따라 자동조절하기 (by konahn) 1
2007.04.17 02:20
9718
47
https://eond.com/20560
object(HotopayModel)#900 (23) { ["error"]=> int(0) ["message"]=> string(7) "success" ["variables"]=> array(0) { } ["httpStatusCode"]=> int(200) ["module"]=> string(7) "hotopay" ["module_info"]=> NULL ["origin_module_info"]=> NULL ["module_config"]=> NULL ["module_path"]=> string(52) "/home/eond/web/eond.com/public_html/modules/hotopay/" ["xml_info"]=> NULL ["module_srl"]=> NULL ["mid"]=> NULL ["act"]=> NULL ["template_path"]=> NULL ["template_file"]=> NULL ["layout_path"]=> NULL ["layout_file"]=> NULL ["edited_layout_file"]=> NULL ["stop_proc"]=> bool(false) ["user"]=> object(Rhymix\Framework\Helpers\SessionHelper)#899 (20) { ["member_srl"]=> int(0) ["user_id"]=> NULL ["user_name"]=> NULL ["nick_name"]=> NULL ["email_address"]=> NULL ["phone_number"]=> NULL ["homepage"]=> NULL ["blog"]=> NULL ["birthday"]=> NULL ["denied"]=> NULL ["status"]=> NULL ["is_admin"]=> string(1) "N" ["is_site_admin"]=> NULL ["profile_image"]=> NULL ["image_name"]=> NULL ["image_mark"]=> NULL ["signature"]=> NULL ["description"]=> NULL ["group_list"]=> array(0) { } ["menu_list"]=> array(0) { } } ["request"]=> object(Rhymix\Framework\Request)#10 (13) { ["method"]=> string(3) "GET" ["compat_method"]=> string(3) "GET" ["url"]=> string(27) "coding/20560/comment/465170" ["hostname"]=> string(8) "eond.com" ["domain"]=> NULL ["protocol"]=> string(5) "https" ["callback_function"]=> string(0) "" ["_route_status":protected]=> int(200) ["_route_options":protected]=> object(stdClass)#11 (5) { ["cache_control"]=> bool(true) ["check_csrf"]=> bool(true) ["is_forwarded"]=> bool(false) ["is_indexable"]=> bool(true) ["enable_session"]=> bool(true) } ["module"]=> string(5) "board" ["mid"]=> string(6) "coding" ["act"]=> string(16) "dispBoardContent" ["args"]=> array(5) { ["page"]=> int(10) ["document_srl"]=> string(5) "20560" ["comment_srl"]=> string(6) "465170" ["mid"]=> string(6) "coding" ["act"]=> string(16) "dispBoardContent" } } ["ajaxRequestMethod"]=> array(2) { [0]=> string(6) "XMLRPC" [1]=> string(4) "JSON" } ["gzhandler_enable"]=> bool(true) }

http://miniwini.com/miniwinis/bbs/index.php?bid=share&m=search&mode=read&id=1114&p=1&keyword=iframe&scale=1&op=and&idx=1설명 : 일반적으로 iframe 을 쓰면 크기를 미리 지정해줘서 보기싫은 스크롤 막대가 생기기 마련입니다.
        그런 경우 자동으로 Iframe 내용에 따라서 문서가 로딩된 후 가로, 세로 크기를 조절해주는 자바스크립트입니다.


예시 :
<HTML>
<HEAD>
<SCRIPT LANGUAGE=javascript>
<!--
function reSize()
{
try{
var oBody = ifrm.document.body;
var oFrame = document.all("ifrm");

oFrame.style.height = oBody.scrollHeight + (oBody.offsetHeight - oBody.clientHeight);
oFrame.style.width = oBody.scrollWidth + (oBody.offsetWidth - oBody.clientWidth);
}
//An error is raised if the IFrame domain != its container's domain
catch(e)
{
window.status = 'Error: ' + e.number + '; ' + e.description;
}
}
//-->
</SCRIPT>
</HEAD>
<BODY onload=reSize()>
<iframeonload=reSize() id=ifrm src=YOUR_PAGE_HEREheight=100%></iframe>
</BODY>
</HTML>

자세한 설명 :
YOUR_PAGE_HERE 라는 부분에 자시의 Iframe 문서를 써주고
링크를 눌렀을 때 아이프레임에 나타나게 하려면 target 을 아이프레임 이름(여기서는 idfrm)으로 주면됩니다.

그리고 스크립트 내부의 try 와 catch 함수는 IE5.0 이하에서 에러가 나면 빼도 상관없답니다.

이와 달리 아래와 같이 아이프레임 문서에서 리사이즈시키는 약간 다른 방법도 있습니다.

http://www.faqts.com/knowledge_base/view.phtml/aid/1076

참조(MS Technet) : http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b278469

※ ifame에 height를 안 적어줘도 IE에서는 됩니다만 파폭은 안되더군요. 그래서 파폭에서도 사용하기 위해서는 <iframe .. height=100%> 를 주었습니다.
하지만 완벽히 IE에서와 똑같이 되지는 않군요. height가 100%가 다 채워진다는 것과 스크롤이 2개가 생기지 않는다는 것 정도.

그리고 src에 다른 사이트의 주소를 넣어주면 작동되지 않습니다. 자신의 계정 안의 문서만 됩니다. 자바스크립트 보안 상의 문제라더군요.
만약 다른 사이트의 주소를 넣어주면 파폭과 똑같이 됩니다. 그렇다면 이 소스는 height를 100%가 작동되게 하는 소스같군요. ^^

라이믹스는 이온디와 함께

  • 이온디
    2007.04.17 20:37
    베스트
    그런데 사용해보니깐잘 안되네요. ;;
HTML5/CSS3
-
+
닫기

마이페이지

로그인을 해주세요

네이버로 로그인