views:

759

answers:

2

Here are two cases: Uppercase as one domain while lowercase as another 1.Suppose window A holds iframe b, and b holds iframe C, A & C in one domain(higher privacy) while b in another. Is there any direct way for communication between A & C, oneway or twoway. 2.Suppose A holds iframe b and iframe c, A is in one domain while B & C in other, just the same question as outlined in the first case.

I will really appreciate your answer, it will be better if with some javascript codes Thanks

+2  A: 

No. Client side communication between frames on different domains is not possible due to the same origin policy.

If it was possible, you could do things like loading a bank website into a frame which fills the entire window, and polling it to see if the user has typed anything in the username and password fields.

If you want to communicate between domains, then there are two approaches. You need to make an HTTP request to achieve either of them.

  1. Pass the information in the URL when loading the page
  2. For information loaded using a <script> element, any code in the loaded JS file from the remote domain will run in the page with the <script> element in it.

You can combine the two approaches:

<script 
  type="text/javascript" 
  src="http://example.com/script.cgi?data=foo;more_data=bar"&gt;
</script>

See JSON-P.

David Dorward
+1  A: 

Yes if they are deliberately cooperating. HTML5 includes the postMessage API for this purpose, and it's implemented in IE8, FF3.5, Chrome, Opera, etc. For downlevel browsers, a "hack" called Fragment Messaging can be used. If you use Flash, you can use Flash Local communication channels.

EricLaw -MSFT-