В скриптах окна А, когда А включен http://example.com:8080:
`var popup = window.open(...popup details...);
popup.postMessage("The user is 'bob' and the password is 'secret'", "https://secure.example.net");
popup.postMessage("hello there!", "http://example.com");`
`function receiveMessage(event) {
if (event.origin !== "http://example.com")
return;
// event.data is "hi there yourself! the secret response is: rheeeeet!"
}`
`window.addEventListener("message", receiveMessage, false);`
Вызывается через некоторое время после вызова postMessage
`
function receiveMessage(event) {
if (event.origin !== "http://example.com:8080")
return;
// event.data is "hello there!"
event.source.postMessage("hi there yourself! the secret response " + "is: rheeeeet!", event.origin);
}`
window.addEventListener("message", receiveMessage, false);