Cross Domain(크로스 도메인) 해결 방법
1. 부모 callback 페이지 호출하기(페이지 전환 됨)
1) 부모->자식 호출 시 callback 페이지명, callback 함수명 파라미터 넘기기
2) 자식->부모 호출 시 요청받은 callback 페이지로 callback 함수와 리턴데이터 넘기기
3) 부모 콜백페이지에서 opener.콜백함수(리턴데이터) 호출
2. iframe & postMessage 사용하기(iframe에서 호출되기 때문에 페이지 전환 없음)
1) 부모페이지 window.addEventListener 선언
($(function){
window.addEventListener("message", 콜백함수명 , false);
});
2) 부모->자식 호출 시 callback 페이지명, callback 함수명 파라미터 넘기기
3) 자식페이지 iframe 생성(부모서버 콜백페이지 호출)
<html>
<iframe id="p_iframe" name="p_iframe" src="부모서버 콜백페이지" display:none;>
<html>
<script>
window.addEventListener("message", function(e){
window.parent.opener.콜백함수명(e.data);
}, false);
</script>
</html>
</iframe>
</html>
4) 자식->부모 호출 시 postMessage를 통해 리턴데이터 넘기기
$(".sendBtn").click(function(e){
var jsonData = 리턴데이터;
document.getElementById('p_iframe').contentWindow.postMessage(JSON.stringify(jsonData), "*");
});