0

I am using Window.postMessage() to call a method from an iframe. Parent page url is http://uir.glassbeam.com, iframe src is http://gbdashboards.glassbeam.com.

When I try to postMessage from iframe, get error on console

Blocked a frame with origin "http://gbdashboards.glassbeam.com" from accessing a frame with origin "http://uir.glassbeam.com". Protocols, domains, and ports must match.

Both url have same Protocols, domains and port,but Error??

Kirween
  • 1,472
  • 1
  • 19
  • 24
Mohammed Raja
  • 207
  • 2
  • 9

1 Answers1

-1

window.postMessage() can safely enables cross-origin communication if and only pages that executed them are at locations with the same:

  • protocol (usually both https)
  • port number (443 being the default for https)
  • host (document.domain set by both pages to the same value)

In your case document.domain does not match for your two scripts, as suggested by your error message you have in fact gbdashboards.glassbeam.com and uir.glassbeam.com as document.domain.

GibboK
  • 71,848
  • 143
  • 435
  • 658
  • Note to future readers, this answer is totally incorrect. _"The `window.postMessage()` method safely enables cross-origin communication between Window objects; [...] Normally, scripts on different pages are allowed to access each other if and only if the pages they originate from share the same protocol, port number, and host. `window.postMessage()` provides a controlled mechanism to securely circumvent this restriction."_ https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage – blex Mar 11 '19 at 13:16