2014-10-30 5 views

답변

1

불행하게도 직접 ​​iframe이의 경계를 넘어 상호 작용할 수 없습니다.

한 가지 해결 방법은 #anchor 값 또는 ?querystring을 포함하도록 iframe 내의 url을 변경 한 다음 부모로부터 iframe의 URL을 읽을 수 있습니다.

+0

및 iframe의 url을 부모로부터 어떻게 읽을 수 있습니까? –

+0

iframe의 DOM 객체에서 'contentWindow.location.href'를 사용할 수 있습니다. 예 : var TheLocation = document.getElementById ('myframe'). contentWindow.location.href; ' –

+0

부모로부터 위치를 설정하여 양방향으로 작동하도록 할 수도 있습니다. –

0

postMessage 시도해 보시기 바랍니다. 자바 스크립트 API이지만 브라우저 제한이 있습니다.

학부모 페이지에 이와 같은 메시지를 게시 할 수 있습니다.

var win = document.getElementById("iframe").contentWindow 

win.postMessage(
    "value", 
    "iframe-domain" 
); 

그리고 은 iframe 페이지이 같은 메시지를들을 수 있습니다.

<script> 
function listener(event){ 
    if (event.origin !== "[parent-page-domain]") 
    return; 

// operate with event.data 
} 

if (window.addEventListener){ 
    addEventListener("message", listener, false) 
} else { 
    attachEvent("onmessage", listener) 
} 
</script> 

SOURCE - http://javascript.info/tutorial/cross-window-messaging-with-postmessage