开发者

Cross-domain if 2 scripts from same domain?

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 do开发者_如何学Pythonmain, 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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜