5***@qq.com
5***@qq.com
  • 发布:2023-04-14 18:34
  • 更新:2023-04-14 18:34
  • 阅读:329

PostMessage安卓端没有触发

分类:HBuilder

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>

2023-04-14 18:34 负责人:DCloud前端团队 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复