A Mootools class that provides cross-domain communication
between an <iframe> element and its parent windows using the
fragment id technique as SOP workaround.
Download and HowTo on Mootools Forge, sources and issues on
GitHub, full documentation
here.
I'm the parent. I received: nothing yet
Test area:
The communication object is instantiated on the parent window this way:
var comm = new CrossDomainFragment({ recipient: $('iframe_element'), onReceive: function(message) { $('inbox').set('text', message); } });
$('send_button').addEvent('click', function() { comm.send($('message').get('value')); });
<iframe src="http://www.example.com/iframe.html" id="iframe_element"</iframe>
Also the page contained in the <iframe>
(which is in a different domain) has to instantiate its own communication object.
You can see that recipient
option is not specified here, because it's window.parent
by default.
var comm = new CrossDomainFragment({ onReceive: function(message) { $('inbox').set('text', message); } });
Thanks to Wang Jiaye and Hu Changchun (IBM) for their excellent work about the fragment id solution.