无法通过webView

时间:2016-07-08 03:51:08

标签: javascript android android-webview postmessage

有两页:a.html,b.html。

在a.html中,我使用window.postMessage()

向b.html发送消息
<input type="text" name=""><input type="button" 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) {
    // if (e.origin ! = ) return;
    $('#name').text(e.data.placeName);
    $('#url').text(e.data.imgUrl);
}
</script>

在b.html中,我听消息事件:

window.addEventListener('message',receiveMessage,false);
function receiveMessage(e) {
    $('#log').text(e.data);
    e.source.postMessage(message,e.origin);
}

浏览器上的代码会在#log元素上显示“hello”,但是当我将页面放在app中时,a.html会收到自己的消息,但是b.html无法显示'hello',它不会收到来自a.html的消息

为什么在webView中代码无法正常工作?

0 个答案:

没有答案
相关问题