简体   繁体   中英

How to get a reference of the content window of the parent window from an iframe, when the parent is cross domain

我需要使iframe可以向它发送一个postMessage。

Because of same origin policy, you have no means to know what is happening is the X-domain child frame. Vice-Versa you have no means to send information up.
However if the other domain is friend of yours, you can establish a communication via the cookies. see also on SO

@Millebi you can do this using following work around.

     <iframe id="frmInner" src="http://www.yahoo.com" height="200" width="200" onload="javascript:$.getScript('Scripts/crossdomain.js',function(){ SomeFunction("someparam"); });">
</iframe>

Where frminner is the frame that displays yahoo page in your site and when loaded completely it calls for a javascript file in you domain ie crossdomain.js , the JS file has SomeFunction() already defined in it which is called with parameter "someparam". Hope this is what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM