gpt4 book ai didi

javascript - 无法在 Cordova 内使用postMessage

转载 作者:太空宇宙 更新时间:2023-11-03 10:47:26 24 4
gpt4 key购买 nike

在我们的 cordova/phonegap-app 中,我们使用 iFrame 加载外部网站。为了与 iFrame 内容进行通信,我为两个站点(应用程序和网站)创建了一个脚本,该脚本使用 iFrame.contentWindow.postMessage() 方法。原因是在智能手机的系统浏览器中的 iframe 中打开外部链接。该解决方案在 cordova 2.3.0 上运行良好。

今天我已经将应用程序的 cordova 版本更新到 3.1.0 并从 android-manifest 中删除了一些权限。但是与 iFrame 内容的通信不起作用。显示以下错误错误消息:

"Unable to post message to https://[domain]. Recipient has origin file://"

要向 IFrame 发布消息,我使用以下代码:

$('#webViewIFrame').get(0).contentWindow.postMessage('message', host);

有人知道为什么我的通信解决方案不适用于 cordova 3.1.0 吗?

最佳答案

一般情况下应该是跨域问题。尝试使用这个:

$('#webViewIFrame').get(0).contentWindow.postMessage('message', '*');

关于javascript - 无法在 Cordova 内使用postMessage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20547835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com