PostMessage 跨域
参考: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
>
Test2
<
script
>
function receiveMessage(e) {
alert(e.data);
}
window.addEventListener("message", receiveMessage, false);
</
script
>
posted on 2015-03-17 21:45 JAVA小书童<bj> 阅读(331) 评论(0) 编辑 收藏 举报