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?

2
  • 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. Commented Apr 3, 2014 at 14:47
  • If I'm not mistake, CORS is for ajax requests between domains. Commented Apr 3, 2014 at 14:47

1 Answer 1

3

You need to use the Web Messaging API.

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.