文書間通信をより広範囲な環境で
動作させるための考察
nanto_vi, 2011-12-08
postMessage
- 文書間通信
- 同一生成元ポリシーを越えられる
- Opera, Firefox, Safari, Chrome and IE 8
iframe.contentWindow.postMessage('Hello', '*');
window.addEventListener('message', function (event) {
alert(event.data);
}, false);
What about IE?
- IE 8 supports
postMessage
- IE 7?
- IE 6!
OK, let's implement XDM in IE 6/7!
隠しフレームと about:blank を用いた文書間通信
デモ

- IE では about:blank の生成元が「about:blank へ遷移させた文書」の生成元と同じ扱いになる……ようだ?
- 親文書と子文書が、ある iframe を about:blank に書き換えあうことで、そのフレームの
window.name
を共有できる
var senderWin = frame.contentWindow[1];
var receiverWin = frame.contentWindow[0];
senderWin.location.replace('about:blank');
senderWin.name = 'Hello, world!'
setInterval(function () {
try {
receiverWin.name;
return;
} catch (ex) {}
receiverWin.location.replace('about:blank');
alert(receiverWin.name);
}, 50);