views:

2055

answers:

3

Hi,

There is a solution called "Fragment Id Messaging" to solve cross domain communication by setting parent.location with extra texts followed by "#" from child iframe, it works. However, if the parent itself is embedded as an iframe in another page, parent.location setting seems denied by browsers... Is this true? If yes, is there a work-around?

Thanks!

+1  A: 

Which browsers are you encountering a problem, and what's the exact error message you see?

Generally, FIM should work correctly even in the scenario you describe, and many major websites use it.

FIM should only be used when the HTML5 postMessage API (supported by IE8, FF3, Chrome, and Opera 10) is not available, as postMessage is more secure and more reliable.

EricLaw -MSFT-
oh, currently i'm using Firefox3.5.1, with error message [Access to property denied" code: "1010]... it looks like a bug reported here http://bit.ly/9xDaU. IE8 does work fine with this. thank you!
Xiao Xu
+2  A: 

Modern browsers which support the postMessage API have increased security which blocks this kind of intra-frame communication. On browsers that don't have this support, the technique you're using should be fine. The only exception to this is Safari 3.2, does not support the HTML 5 postMessage API and will not allow you to set parent.location in certain circumstances.

The other gotcha is that while IE8 has implemented the postMessage API, it has (somewhat predictably) done it differently from all the other browsers (FF3+, Chrome, Safari 4+ and Opera 9.64+). With IE8, postMessage communication between a popup and it's opener is not allowed, meaning you need to use an extra iframe for IE8 that is not required for any other browser.

The end result is that, to implement communication between a page and popup window on a remote domain, you need one branch for decent modern browsers, one for older browsers, and a separate one each for IE8, IE7 and IE6. Thanks Microsoft...

祝你好運 :)

simon
got it, thanks!
Xiao Xu
On the USA's national anthem: O'Lord can you see, how IE is crap?
Andrew Moore
A: 

Hi All,

I used the same technique o solve cross domain communication.

but this works fine in FF but not in chrome and safari.

Specially following code: parent.window.location.hash = "#blablabla";

any solution?

Onkar