For say i have a Site called example.com on which iframe is embedded of domain iframe.net, now i want to read the content of iframe and pass some parameter to display a text
In Internet Explorer 8, events passed as a parameter may be null, that is why you need to access the event in a different manner:
In frame.html:
window.onmessage = function(event) {
var evt = event || window.event;
evt.source.postMessage('Message from iFrame', evt.origin);
};
On main.html:
window.onmessage = function(event) {
var evt = event || window.event;
alert(evt.data);
};
The event is triggered the same way as Rob W has presented:
document.getElementById('frameId').contentWindow.postMessage('message','*');