uniapp(h5 app) 中 webview和h5通信

1 uniapph5    和h5页面 通信

h5 

window.parent.postMessage(message, '*');

uniapph5   onload中 

window.addEventListener('message', function (e) {
        // 监听 message 事件
        //console.log(e.origin)
        console.log('收到的cocos游戏ID',e.data)
        //收到cocos退出游戏返回的指令
        if(e.data){
            uni.navigateTo({
                url:`/pages/salason/salason?id=${e.data}`
            })
        }
    })

2 uniapp app 中 和h5通信

h5  index.html中 引入

你可能感兴趣的:(uni-app)