Iframe nested cross-domain

Here are two cases: Upper case as one domain and lower case as another. 1. Iframe b is executed in window A, b contains iframe C, A and C in one domain (higher privacy), and b in another. Is there any direct way to communicate between A and C, one-way or two-way. 2. Suppose A contains iframe b and iframe c, A is in one area, and B and C are in another, just the same question as in the first case.

I will be very grateful for your answer, it would be better if with some javascript codes Thanks

+1
source share
2 answers

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

If it were possible, you could do something like loading the bank's website into a frame that fills the entire window and poll 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 reach any of them.

  • Pass the information to the URL when the page loads
  • For information loaded using the element <script>, any code of the downloaded JS file from the remote domain will be launched on the page with the element <script>.

You can combine two approaches:

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

See JSON-P .

+3

, . HTML5 postMessage API IE8, FF3.5, Chrome, Opera .. , " Fragment Messaging. Flash, Flash Local .

+7

All Articles