2016-10-20 6 views
0

Currenlty私はコードサイトアプリ内でオンラインサイトに埋め込みます。私のconfig.xmlには以下の通りです:iframeにcordovaコマンドを実行させる

<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: Blocked a frame with origin "http://" from accessing a frame with origin "file://". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "file". Protocols must match.

このような種類の外部サイトからアプリケーションへの対話を許可するにはどうすればよいですか?

答えて

0

CORSとサンドボックスのためiframeはこの種の通信を処理するための正しい方法ではありません。

コルドバにはInAppBrowserというプラグインがあります。

cordova plugin add cordova-plugin-inappbrowser

、それは私たちがexecuteScript方法使用messaggingの種類とブラウザウィンドウと対話することができます:我々はそれをインストールすることができます

var myRef = cordova.InAppBrowser.open('http://<site>', '_blank', 'location=no'); 

myRef.executeScript({ code: "localStorage.setItem('demo', '');" }); 
関連する問題