Blocked a frame with origin "myMainPage.com" from accessing a cross-origin frame

Viewed 34

Hi there I'm getting this error in the console, this is my code on my iframe that accepts the request I think, as said in https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage;

window.addEventListener('message', event => {
            if (event.origin.startsWith('https://axe-uat.unileversolutions.com/')) { 
                console.log(event.data); 
            } else {
                return; 
            } 
        });

When I try to send a simple message it shows me error in console;

This is my code on my main page where I'm trying to access the iframe document;

  x = document.querySelector('iframe');

  var xWin = x.contentWindow;
   
  xWin.postMessage("message", "*");
    
 

Thanks a lot

0 Answers
Related