参考:http://www.ibm.com/developerworks/cn/web/1301_jiangjj_html5message/
Test 2 send to Test 1
Test 1:
<iframe src="http://10.3.255.203:8080"></iframe>
<script>
function receiveMessage(e) {
alert(e.data);
}
window.addEventListener("message", receiveMessage, false);
</script>
Test 2:
<input type="text" value="send" id="input" />
<input type="button" value="send" id="button" />
<script>
document.getElementById(‘button‘).onclick = function () {
top.postMessage(document.getElementById(‘input‘).value, ‘*‘);
};
</script>
Test1 send to Test2
Test1
<
iframe
id
=
"frame"
src
=
"test2.html"
></
iframe
>
<
input
type
=
"text"
value
=
"send"
id
=
"input"
/>
<
input
type
=
"button"
value
=
"send"
id
=
"button"
/>
<
script
>
document.getElementById(‘button‘).onclick = function () {
window.frames[0].postMessage(document.getElementById(‘input‘).value, ‘*‘);
};
</
script
>
<
script
>
function receiveMessage(e) {
alert(e.data);
}
window.addEventListener("message", receiveMessage, false);
</
script
>
原文:http://www.cnblogs.com/architects/p/4345628.html