首页 > 代码库 > web message

web message

//发送信息
var iframeWindow = document.querySelector( "iframe" ).contentWindow;
iframeWindow.postMessage( "a message", "http://www.webMessagePost.com" ); //向iframeWindow发送的信息和表明自己身份


//监控信息
W.addHandler( window, "message", function ( event ) {
if ( event.origin == "http://www.webMessagePost.com" ) { //验证发送消息的域是已知的域

var data = http://www.mamicode.com/event.data; //do something

//可选:向来源窗口发送回执
event.source.postMessage( "I received your present", "http://www.hello.com" );
}
} )

web message