I'm getting two errors when running the following code in my React application:
try {
iframe.src = applicationRoutes.href;
iframe.style.width = '0px';
iframe.style.height = '0px';
iframe.style.border = '0px';
iframe.style.display = 'none';
iframe.id = 'iframe';
iframeRef.current.appendChild(iframe);
const myIframe = window.frames['iframe'].contentWindow;
myIframe.postMessage('user info', applicationRoutes.href);
} catch (error) {
console.log(error);
}
The errors I receive are the following:
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://localhost:3000') does not match the recipient window's origin ('http://localhost:4001').
and
Refused to display 'http://localhost:3000/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
What can I do to fix these issues?
X-Frame-Optionsheader to the iframehttp://localhost:3000/? Also, from your browser's console, if you typewindow.frames['iframe'], does the output match the iframe you expected? Finally, what is athttp://localhost:4001?