window.postMessage("Hello","portal.**.com");
//发信息给Iframe
document.getElementsByTagName("ifram")[0].contentWindow.postMessage("Hello","portal.**.com");
监听消息事件
var originWhiteList = ["www.***.com","www.***.net"];
function checkWhiteList(origin)
{
for(var i=0;i<originWhiteList.length;i++)
{
if(orgin == originWhiteList[i])
{
return true;
}
}
return false;
}
function messageHandle(e){
if(checkWhiteList(e.origin))
{
processMessage(e.data);
}
else{
//忽略消息
}
}
window.addEventListener("message",messageHandle,true);