2

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);
John Brunner
  • 2,842
  • 11
  • 44
  • 85
  • You still need to control both websites. Do you own `domain.de`? – zer00ne Dec 06 '16 at 09:26
  • 1
    Yes. I control the first page, and the third page, but not the second one in the middle. And I want to catch a `postmessage` on the third page (`domain.de`). – John Brunner Dec 06 '16 at 10:12
  • I just answered a similar question [here](http://stackoverflow.com/a/40992214/2813224) see if that's any help. – zer00ne Dec 06 '16 at 10:27

0 Answers0