Uniapp 打包出来的安卓端App,页面中向iframe的窗口发送postmessage消息,但是在iframe对应的window中对应的监听函数没有触发。
webgl的html中:
function ReportReady(str)
{
g_unityInstance.SendMessage("JsTalker","SetToken",JSON.stringify(str));
}
window.addEventListener("message",(e)=>{
console.log("iframe="+e.data);
g_unityInstance.SendMessage("JsTalker","SetToken",JSON.stringify(e.data),false);
});
页面vue文件中
<template>
<view>
<view @click="jumpback">
<button>回到主页面</button>
</view>
<view @click="donghua">
<button>发信息到unity</button>
</view>
<view>
<iframe name ="crossframe" id ="iframe" ref= "iframe" class="iframe" src = "http://192.168.100.120/ServerFolder/Jacky/Communication/index.html" width ="100%" height="100%" frameborder = "0" scrolling="yes" />
</view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
jumpback()
{
uni.redirectTo({
url:"/pages/index/index"
})
},
donghua(){
//var f =document.getElementById("iframe");
const iframe = window.frames["crossframe"];
iframe.postMessage("Vue Send message to Unity success","*");
//iframe.Message("JsTalker","SetToken","Vue Send message to Unity success");
}
}
}
</script>
0 个回复