javascript - iframe 的安全错误

标签 javascript android cordova iframe sencha-touch

以下问题出现在Android 4.4及以上的设备上。

这是我们的 iframe 的样子:

<iframe frameborder=0 id="myIFRAME"></iframe>

以下是我们以编程方式获取 iframe 的方式:

if(document.getElementById("myIFRAME")){
        me.setMyIFRAME(document.getElementById("myIFRAME").contentWindow);
}

这会导致与协议(protocol)不匹配相关的安全错误:

"Uncaught SecurityError: Blocked a frame with origin "https://www.google.com" from accessing a frame with origin "file://". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "file". Protocols must match.

我们使用 Sencha touch 和 Cordova 来开发我们的项目。

最佳答案

Cordova security guide说:

If content is served in an iframe from a whitelisted domain, that domain will have access to the native Cordova bridge.

您是否尝试过添加外部域 to the whitelist里面 config.xml?

<access origin="https://google.com" />

关于javascript - iframe 的安全错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32437226/

相关文章:

java - 如何在 Android 中创建 Accordion ListView?

android - 我的 shell 脚本没有在 android 上运行

cordova - wikitude 增强现实应用程序使用增强现实

javascript - 使用 jQuery slider 显示值范围

javascript - 使用 Jquery 正则表达式在空格后添加 diez 标签

java - 如果单词对于 TextView 来说太长,则强制下一个单词换行

android - 如何使用 Cordova 文件插件读取/写入 Android/iOS 设备子目录中的文件?

javascript - 如何使用 javascript 在 Phonegap 的推特上发布图片

javascript - 创建时重新获取 Backbone 集合

javascript - 正则表达式 (javascript) 允许\w 但不允许单个指定单词