: 도메인이 다를경우 크로스 도메인 정책으로 인해 정상적인 방법으로는 값을 전달하기가 힘들다. 타겟 페이지로는 값이 전달되나 타겟 페이지에서 타켓을 호출한 페이지로는 도메인이 다를경우 전달할 수 없다.
1. http://aaa.com/guidebook.jsp
<scritp type="text/xxjavascript" src="guidebook.js"></script>
<dl>
<dd>
<div id="guidebook_result_container">
<iframe src="" name="frameGuidebook" id="frameGuidebook" width="670px" height="" frameborder=0 scrolling="no"></iframe>
</div>
</dd>
</dl>
$.iframeView=function(guidebook_url){
//var _html = '<iframe src="" name="frameGuidebook" id="frameGuidebook" width="685px" height="" frameborder=0 scrolling="no"></iframe>';
$('#center_BookContent_area2').hide();
$('#center_BookContent_area1').show();
//$('#guidebook_result_container').show().html(_html);
$('#frameGuidebook').attr('height','450px'); // iframe 삽입전 항상 height를 초기화한다.
$('#frameGuidebook').attr('src',guidebook_url);
};
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<script type="text/xxjavascript">
/*
http://bbb.com/contents1.jsp 페이지에서 넘어온 height 값과 height 값을 변경할 iframe
의 id값을 전달 받는 부분.
여기서 전달받은 값으로 guidebook.jsp 페이지내 iframe의 height 값을 변경한다.
*/
window.[안내]태그제한으로등록되지않습니다-xxonload = function(){
var params = window.location.search.substring(1).split("&");
var height;
var iframeName;
for( var i=0, l=params.length; i<l; ++i )
{
var parts = params[i].split("=");
switch( parts[0] )
{
case "height":
height = parseInt(parts[1]);
break;
case "iframeName":
iframeName = parts[1];
}
}
// alert(height);
if( typeof( height ) == "number" )
{
var iframe = parent.parent.document.getElementById(iframeName);
iframe.setAttribute("height", height);
}
};
</script>
</body>
</html>
2. http://bbb.com/contents1.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta name="Author" content="KIPRA 한국지식재산보호협회">
<meta name="Keywords" content="KIPRA, 한국지식재산보호협회, 해외 지재권 분쟁 가이드북">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!--<meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,initial-scale=1.0">-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=medium-dpi"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name = "format-detection" content = "telephone=no"/>
<link rel="stylesheet" type="text/css" href="../css/layout.css"/>
<TITLE>가. 국가 일반현황</TITLE>
<script type="text/xxjavascript" language="xxjavascript" src="../js/ip-navi_google_analytics.inc "></script>
<script type="text/xxjavascript" language="xxjavascript" src="../js/common.js"></script>
</HEAD>
<BODY>
<P class="BigText">가. 국가 일반현황</P>
<P class="BigSText">United States of America</P>
<P><SPAN class="BigSSText">국가 :</SPAN> 성조기</P>
<P style="text-indent:1em">2009년 미국 경제에서 개인 부문은 전체 중 55.3%를 차지하는 것으로 집계되었는데, 연방 정부 활동은 24.1%, 주 및 지역 정부 활동(연방 이전액 포함)은 20.6%를 기록하였다. 미국 경제는 탈산업화 단계로, 서비스 부문이 GDP의 67.8%를 차지하지만, 지금도 미국은 산업 강국이다. 기업 총수령액 기준 주요 사업 문야는 도소매 무역이며, 순수입 기준으로는 제조업이 주된 분야이다. 화학 공학 제품은 주요 제조업 분야이다. 미국은 세계 3위 석유 생산국이며, 최대 수입국이기도 하다. 미국은 전기 및 핵 에너지를 비롯하여 액화 천연 가스, 황, 인지질, 소금 생산에서 세계 1위이다. 농업은 미국 GDP의 1%를 넘지 않으나, 미국은 옥수수와 콩의 세계 최대 생산국이다. 뉴욕 증권거래소는 세계에서 달러가 가장 많은 곳이다. 코카콜라, 맥도날드는 세계에서 브랜드 인지도가 가장 높은 기업이다.</P>
<P>출처 : <A HREF="http://ko.wikipedia.org/wiki/%EB%AF%B8%EA%B5%AD" TARGET="_self">Wikipedia 미국</A></P>
<P align="center"><input type="button" name="next" value=" ◀" style="color:white;"> <input type="button" name="next" value=" ▶" style="color:black;" [안내]태그제한으로등록되지않습니다-xxonclick="location.href='../I002/I002_C01_F01.html'"></P>
<iframe src="" name="frameGuidebook" id="frameGuidebook" width="685px" height="" frameborder=0 scrolling="no"></iframe>
<script type="text/xxjavascript" src="/js/iframe.js"></script>
</BODY>
</HTML>
/**
* 가이드북 iframe 사이즈 조절을 위해 자식 iframe쪽의 height를 ip-navi 쪽으로 넘겨주기 위한 설정.
*/
var iframe = document.getElementById("frameGuidebook");
var height = 0;
//alert(document.body.offsetHeight);
//alert( document.body.scrollHeight);
height = Math.max(document.body.offsetHeight, document.body.scrollHeight);
iframe.src = "http://aaa.com/iframeDispatcher.jsp?height="+ height + "&iframeName=frameGuidebook";
--> http://bbb.com/content1.jsp 페이지의 height값과 iframe id값을 http://aaa.com/iframeDispatcher.jsp 페이지로 넘겨준다.
로직 순서는 아래와 같다.
1. http://aaa.com/guidebook.jsp 페이지에서 iframe으로 http://bbb.com/contents1.jsp 페이지를 호출한다.
2. http://bbb.com/contents1.jsp 페이지에서 iframe을 이용해서 http://aaa.com/iframeDispatcher.jsp로 contents1.jsp height 값을 넘겨준다.
3. http://aaa.com/iframeDispatcher.jsp 페이지에서 height 값을 전달받아서 같은 도메인내의 guidebook.jsp 페이지의 iframe의 height 값을 변경한다.