3

I have an iframe in a domain "someplace.com" being loaded into "anotherplace.com" 's window.

Old questions say you can't access variables across domains: Sharing global javascript variable of a page with an iframe within that page

But now that we have CORS, I'm wondering if this is possible. Are we now able to access JS variables in an iframe's parent if we enable CORS between the domains?

Community
  • 1
  • 1
Don P
  • 60,113
  • 114
  • 300
  • 432
  • CORS is about HTTP requests – so if you want to transfer the value via HTTP, that could be a way to go, but it is not direct access to a variable. `postMessage` would be an alternative to transfer data between window instances from different domains. – CBroe Apr 03 '14 at 14:47
  • If I'm not mistake, CORS is for ajax requests between domains. – Laurent S. Apr 03 '14 at 14:47

1 Answers1

3

You need to use the Web Messaging API.

https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage

Ray Nicholus
  • 19,538
  • 14
  • 59
  • 82
David Bradshaw
  • 11,859
  • 3
  • 41
  • 70