blog
[iframe] 도메인이 다른 부모-자식 창 간의 통신 본문
Uncaught DOMException: Blocked a frame with origin "도메인" from accessing a cross-origin frame.
iframe에서 도메인이 다른 부모창 - 자식창 간의 통신(cross-origin error)
1
2
3
4
5
6
7
|
var data = "datatatatatata";
var iframe = document.getElementById("iframe_id");
var iframe_document = iframe.contentDocument || iframe.contentWindow;
iframe_document.postMessage(data,"http://localhost:56007자식주소");
|
cs |
부모 javascript
1
2
3
4
5
6
7
8
|
window.addEventListener("message", postMessageController, true);
function postMessageController(e) {
// 보안성으로 보낸 페이지 체크 한다.
if (e.origin === 'http://localhost:부모주소') {
alert(e.data); // 전송 받은 데이터
}
}
|
cs |
자식 javascript
'Web > front-end' 카테고리의 다른 글
[DataTables] ajax 통신으로 데이터를 받아서 테이블에 넣기 (0) | 2022.03.16 |
---|---|
[Javascript] 앞글자가 ~으로 시작하는 element의 id 찾기 (0) | 2022.03.14 |
[DataTables] 선택 한 데이터를 클립보드에 복사하기 (0) | 2022.03.14 |
alert [object Object] (0) | 2022.03.14 |
[DataTables] row Select 기능 추가(선택한 행의 data 값 가져오기) (0) | 2022.03.05 |