2017-04-20 5 views
0

beforeunload 창 이벤트에서 postMessage()이 호출되면이 메시지는 부모에게 전달되지 않습니다. 동일한 메시지가 unload 또는 load 이벤트에 게시되면 성공적으로 수신됩니다. JQuery와에 :이 경우beforeunload에서 postMessage가 실패합니다.

$(window).on('beforeunload', function() { 
    parent.postMessage('TheMessage', 'domain.com'); //NOT received by parent 
});  

$(window).on('unload', function() { 
    parent.postMessage('TheMessage', 'domain.com'); //Received by parent 
}); 

$(window).load(function(){ 
    parent.postMessage('TheMessage', 'domain.com'); //Received by parent 
}); 

우리는 부모에 IFrame을에서 게시하는 두 웹 페이지는 동일한 소유자에 의해 제어하지만 서로 다른 도메인에서 제공된다.

이것은 예상되는 동작입니까? 나는 alert is not allowed in beforeunload하지만 postMessage에 대한 규칙이 표시되지 않는 것을 볼 수 :

2011년 5월 25 일 이후, 는 Window.alert(), window.confirm() 및 window.prompt에 호출 HTML5 규격 상태 () 메서드는이 이벤트 중에 무시됩니다.

postMessage을 사용할 수 있습니까?

답변

0

이것은 iOS에서만 발생하며 변경 방법이없는 것으로 보입니다. Android에서는 beforeload가 예상대로 실행됩니다.