공부/uncategorized
[cross domain] window.postMessage
doublemetal
2015. 9. 2. 10:40
popup <-> opener간 통신을 위한 코드
- opener 에 message listen 이벤트 구현
window.onmessage = function(e){
if(e.origin.indexOf('tistory.com') < 0){
return;
}
if(e.data.type == 'test'){
alert(e.data);
}
};
if(e.origin.indexOf('tistory.com') < 0){
return;
}
if(e.data.type == 'test'){
alert(e.data);
}
};
- popup
window.open("http://tistory.com", "popup",
"scrollbars=no,toolbar=no," +
"location=no,resizable=no," +
"status=no,menubar=no,width=444,height=365");
- popup window에서 실행
opener.postMessage(eval('({"type":"test"})'),'http://tistory.com');
"scrollbars=no,toolbar=no," +
"location=no,resizable=no," +
"status=no,menubar=no,width=444,height=365");
- popup window에서 실행
opener.postMessage(eval('({"type":"test"})'),'http://tistory.com');