We have two javascript files in separate domains. for communication between them we are using postMessage(). IE not supporting the postMessage() between cross-domain in popup windows. Any solution for this??
There is couple of solutions for this.
The simplest one is to actually make so that popup opens html-page from the same domain as the parent page, and this page contains one iFrame that fills the whole popup. The iframe then refers to the other domain. This way IE doesn't need to use postmessage between main page and the popup, the postmessage happens between popup and the iframe, which is supported by all browsers.
it can rougly look like this:
Main page
<html>
<head>
<script>
var popup = null;
$(document).ready(function() {
popup = window.open("Popup.html");
}
function DoStuff() {
popup.SendMessage("Hello World");
}
</script>
</head>
<body>
<button onclick="javascript:DoStuff()">Test</button>
</body>
</html>
Popup.html (in same domain as Main Page)
<html>
<head>
<script>
function SendMessage(message) {
$("#targetIframe").contentWindow.postMessage(message, '*');
}
</script>
</head>
<body>
<!-- TODO: fill whole window with css -->
<iframe id="targetIframe" src="http://otherdomain/Target.html"/>
</body>
</html>
Target.html should do then normal postmessage receiving stuff.
This solution works in any browser. There is also ready made crossdomain communication library called porthole (http://ternarylabs.github.io/porthole/), it uses postmessage if browser supports it. I have used it and it works nicely. Problem is that it is bit complex to setup, and therefore I would suggest using this popup iframe trick.