iframe があり、iframe から親ウィンドウにデータを送信したいと考えています。
iframe の js コード内に、次のステートメントがあります。
window.parent.postMessage('hello', '*');
親ウィンドウの対応するメッセージ ハンドラは次のとおりです。
$(window).bind('message', function (event) {
console.log(event.data);
console.log(event.origin);
console.log(event.source);
console.log('received');
});
localhost からコードを読み込んでおり、iframe ソースも localhost から読み込まれています。私はFirefox 21でコードを実行しています。
問題は、event.data
常にnull
であり、event.orign and event.source
であるということですundefined
。この問題を解決するにはどうすればよいですか?