I found this samplefrom SO while browsing for my problem, but I want to know exactly how to use it in my scenario. I have an iframe which is from another domain, and I want
You need to set targetOrigin when using postMessage.
Then on the host page.
function addAnEventListener(obj,evt,func){
if ('addEventListener' in obj){
obj.addEventListener(evt,func, false);
} else if ('attachEvent' in obj){//IE
obj.attachEvent('on'+evt,func);
}
}
function iFrameListener(event){
secondPageValue = event.data;
}
var secondPageValue='';
addAnEventListener(window,'message',iFrameListener);