Execute javascript function in another iframe when parent from another domain

A.com page has 2 iframes B.com/page1 and B.com/page2 . This is the A.com code:

<html><body> <iframe src="b.com/page1" name="iframe1" id="iframe1"> <iframe src="b.com/page2"> </body></html> 

I want to execute the js function on B.com/page1 from B.com/page2 . Both examples below work well when the parent is from the same domain, but not in a cross-domain scope scenario:

 parent.window.frames['iframe1'].SomeFunction(args); 

or

 parent.document.getElementById('iframe1').contentWindow.SomeFunction(args); 

Is there any way to do this?

+6
javascript xss cross-domain iframe
source share
4 answers

Instead

 parent.window.frames['iframe1'].SomeFunction(args); 

using

 parent.frames['iframe1'].SomeFunction(args); 

You are allowed to cross the frames collection of any window that you can reference, but in this case you are trying to cross the recursive window parent property (which is the window). This is not allowed.

+7
source share

No, the browser does not allow interaction between iframes that are not in the same domain at all.

+3
source share

As Aaron already told you, browsers do not allow this, but there are ways around. You will need to create a small hack. Evgeny Gladyshev posted a post on his blog .

0
source share

According to Aaron, interaction between iframes is not allowed, but you should take a look at easyXDM, this helps with cross-domain communication in javascript:

http://easyxdm.net/wp/

Here is an example you can look for:

http://easyxdm.net/wp/2010/03/17/sending-and-receiving-messages/

0
source share

All Articles