这是一个适用于Chrome 5.0.375.125的示例。
网页B(iframe内容):
<html> <head></head> <body> <script> top.postMessage('hello', 'A'); </script> </body></html>注意使用
top.postMessage或
parent.postMessage不
window.postMessage这里
页面A:
<html><head></head><body> <iframe src="B"></iframe> <script> window.addEventListener( "message", function (e) { if(e.origin !== 'B'){ return; } alert(e.data); }, false); </script></body></html>A和B一定是这样的
http://domain.com



