webView中页面无法接受到postMessage发出的消息
有两个页面:a.html b.html,在a中利用postMessage方法向b发送消息,并设置消息监听事件,代码如下:
$('input[type="button"]').on('click',function () {
var mapWindow = window.open('d.html?s=' + $('input[type="text"]').val() + '&nw=1');
setTimeout(function () {
mapWindow.postMessage('hello', 'http://192.168.199.191:8080');
},10000);
})
window.addEventListener('message',receiveMessage,false);
function receiveMessage(e) {
$('#name').text(e.data.placeName);
$('#url').text(e.data.imgUrl);
}
然后在b页面监听message事件,代码如下:
window.addEventListener('message',receiveMessage,false);
function receiveMessage(e) {
// if (e.origin !