views:

104

answers:

2

I have a JS file that puts an iframe on every site its on.
both the JS and the iframe location comes from the same domain, mine.

Can I somehow communicate from within the iframe to the outside script,
which isn't running on my domain, but is called from it?

I know about JSONP but i'm looking for a better way if possible

+1  A: 

It's very simple. The location of the document needs to be served from the same domain as the location of the script. Otherwise, the script will get "Access Denied" error.

Josh Stodola
ok. simple it is! :) just wanted to make sure.
vsync
A: 

If you are supplying a script for other people to use, then you could have them load easyXDM which would allow your script to communicate with the document loaded in the iframe (if it also has the easyXDM library set up). You would also have to require them to host a simple html file on their domain in case easyXDM cannot use postMessage and has to resort to using the hash/fragment solution.

Demos of this can be viewed here

Sean Kinsey