Currenlty我在一个cordova应用程序中嵌入在线网站;我的config.xml如下:
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<allow-navigation href="*" />
我的index.html有以下元标记:
<meta http-equiv="Content-Security-Policy" content="default-src *;
style-src * 'self' 'unsafe-inline' 'unsafe-eval';
script-src * 'self' 'unsafe-inline' 'unsafe-eval';">
现在我需要从内部网站执行一个codova命令(应用程序),我正在使用以下代码:
window.parent.cordova.plugins.barcodeScanner.scan(function (result) {},
function (error) {});
但是(正确地)失败了:
Uncaught SecurityError:阻止具有原点的帧 “http://”访问具有原点的帧 “文件://”。请求访问的帧具有协议“http”,即 被访问的帧具有“文件”协议。协议必须匹配。
如何允许从外部网站到我的应用的这种互动?
答案 0 :(得分:0)
由于CORS和沙箱,iframe定义不是处理此类通信的正确方法。
在Cordova有一个名为InAppBrowser
的插件;我们可以安装它:
cordova插件添加cordova-plugin-inappbrowser
它允许我们使用<html lang="en">
<head>
<!-- Basic Page Needs-->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>ABC</title>
<!-- Mobile Specific Metas-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSS-->
<link href="<?php echo base_url(); ?>assets/css/style.css" rel="stylesheet">
</head>
<body>
方法与浏览器窗口进行交互:
executeScript