开发者

cross domain iframe communication: can't read child's src

I have an iframe and I want to send a message from the iframe to its parent window. That's what child does

window.location += '#do_install||something';

That's what parent does ($ is jquery)

setTimeout('alert($("iframe#main_store_frame").attr("src"));', 5000);

I've tried many other ways to detect that location change but all of them fail. They all show me the initial iframe location, not a new one with '#do_install||something' added. Please let mw know w开发者_Python百科hat I am doing wrong.


You have several option to do that:

1 Use the window.name (in iframe) and iframe.contentWindow.name (in parent) . the idea is actually to change your iframe name (from your iframe)

IFRAME: window.name = "new value"

and use the iframe.contentWindow.name from your parent window (while "iframe" is your iframe object)

PARENT: console.log(iframe.contentWindow.name)

You may read the following article for more information

2 Use HTML 5 window.postMessage. You may find an exmaple here.

the idea is to be able to set a connection between parent window and the iframes while using an access list by domain. If you are using jQuery you may use jQuery exmaple

Another project is xAuth " is an open platform for extending authenticated user services across the web."

to sum-up

if you have the ability to control both parent and iframes (at least request your partners to submit your code into their page) you will have the permission for cross domain communication

** sorry for not printing the examples here, they are just too long.

hope I helped.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜