La documentazione per postMessage implica che la messaggistica tra domini è possibile. Tuttavia:Come posso eseguire postMessage su più domini?
// When the popup has fully loaded, if not blocked by a popup blocker
Che non è molto chiara nota del come a farlo davvero.
Immaginate due siti web:
- [Parent] ospitato su
qc-a.nfshost.com
- [Bambino] ospitato su
qc-b.quadhome.com
nel genitore:
document.addEventListener('message', function(e) {
alert('Parent got (from ' + e.origin + '): ' + e.data);
e.source.postMessage('Round-tripped!', 'http://qc-b.quadhome.com');
}, false);
function go() {
var w = window.open('http://qc-b.quadhome.com', 'test');
/* This doesn't work because same-origin policy prevents knowing when
the opened window is ready. */
w.postMessage('Vain attempt.', 'http://qc-b.quadhome.com');
}
E, nel child:
document.addEventListener('message', function(e) {
alert('Child got (from ' + e.origin + '): ' + e.data);
}, false);
window.opener.postMessage('Ready!', 'http://qc-a.nfshost.com');
Tutto inutilmente.
Aiuto?
In breve, sono un idiota. Sostituito 'document' con' window' e il callback pronto ha funzionato tramite 'window.opener.postMessage'. Grazie! –
Succede al meglio di noi :) –