I have an iframe in my Ionic/Cordova application. When I'm doing a postMessage
, everything works fine, and I can retrieve the message in the parent-window. But when the page inside the iframe redirects to another URL, and then this URL redirects back the the previous URL (my server), non of my postMessages are going to be emitted (specifically: I can't retrieve them in the parent-window anymore).
Is this normal behavior? How can I achieve my goal?
In the iframe window I have the following code:
setTimeout(function() {
parent.postMessage("error", "*");
},3000);
And in the parent-window (in the app) I have the following code:
var eventListenerFunc = function(event) {
// Checking the origin of the data!
if (~event.origin.indexOf('http://www.domain.de')) {
if(event.data == 'success'){
...
$ionicHistory.goBack();
deleteEventListener();
} else if(event.data == 'cancel'){
...
$ionicHistory.goBack();
deleteEventListener();
} else if(event.data == 'error'){
...
$ionicHistory.goBack();
deleteEventListener();
}
} else {
deleteEventListener();
return;
}
};
var eventListener = window.addEventListener('message', eventListenerFunc);