为了账号安全,请及时绑定邮箱和手机立即绑定

webView中页面无法接受到postMessage发出的消息

webView中页面无法接受到postMessage发出的消息

繁星coding 2018-08-10 08:09:05
有两个页面:a.html b.html,在a中利用postMessage方法向b发送消息,并设置消息监听事件,代码如下:<input type="text" name=""><input type="button" name="" value="search"><p id="name"></p><p id="url"></p><script type="text/javascript">     $('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);     }</script>然后在b页面监听message事件,代码如下:window.addEventListener('message',receiveMessage,false);function receiveMessage(e) {    // if (e.origin ! = ) return;     $('#log').text(e.data);     e.source.postMessage(message,e.origin); }此代码在浏览器中可以正常运行,在b页面中成功输出信息“hello”,但是将页面放到app里面后,b无法接受到a的消息,经测试a的消息可以发出,a自己可以接受到自己的消息,但是b却没有接受到消息。
查看完整描述

1 回答

?
慕无忌1623718

TA贡献1744条经验 获得超4个赞

你需要设置你的WebView支持multiple windows。


查看完整回答
反对 回复 2018-09-21
  • 1 回答
  • 0 关注
  • 4875 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信