I'm trying to implement communication with postMessage. There is the main page which opens a popup with an iframe which comes from a different domain. This works fine so far but I want to catch the following error which occurs when I open the iFrame with a wrong origin.
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('myOriginURL') does not match the recipient window's origin ('myWindowsOrigin').
origin = 'http://www.myorigin.ch';
if (window.postMessage) {
try {
top.postMessage('hello', origin);
}
catch(ex) {
alert('an error occured');
}
}
the problem is that the code never runs into the catch block. Interesting part is that chrome shows an error in the console while all other major browser just don't do anything (no alert, no error)
How can I handle the error in the postMessage?