I have created PostMessage from one domain to another.
in domain A I have frame of domain B. I can send message from A to B. now I want to do opposite of that. I need a button in the frame (on popUp windows). when I click there, I need to send message from B to A.
On domain A:
<iframe id="frameId" src="http://b.net/2.html" onload="sendCommand();"> </iframe>
<script type="text/javascript">
function sendCommand() {
var receiver;
receiver = document.getElementById('frameId').contentWindow;
receiver.postMessage(receiver, 'http://b.net');
}
</script>
</body>
</html>
And in Domain B:
<!DOCTYPE HTML>
<html>
<head>
<script>
var F= function(){}
</script>
</head>
<body>
Hello THere
<button onclick="F()">Click me</button>
<script>
window.addEventListener('message', function(event) {
alert(event.origin);
}, false);
</script>
</body>
</html>