-1

currently I've this code to post a message to the parent window:

  const onSomething = () => {
    window.parent.postMessage('hey', 'https://www.google.com')
  }

And inside the parent window, I'm accessing the document and send some data back to the iframe.

My question is, can I access the window parent document inside my application(A.K.A the iframe) or only the parent window can access his document?

If I'm calling window.parent.document from my application I'm getting this error:

SecurityError: Blocked a frame with origin "http://localhost:3000" from accessing a cross-origin frame.

NOTE: The parent window and the iframe are different origins

ScrapeW
  • 489
  • 8
  • 16

1 Answers1

0

As your posted error message lets you know, this is blocked by any modern web browser for security reasons.

For more details, maybe this MDN article can be interesting for you: https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy#cross-origin_script_api_access