2016-10-01 3 views
0

こんにちは私はコードワを初めて使用します。 私のウェブサイトを表示するアプリケーションを作成したい。ここコルドバInAppBrowserが機能しない

アプリを作成するために、私のコルドバコマンドです:

cordova create myapp 
cd myapp 
cordova platform add android --save 
cordova plugin add cordova-plugin-inappbrowser --save 

とのindex.html:

<html> 
    <head> 
     <!-- 
     Customize this policy to fit your own app's needs. For more guidance, see: 
      https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy 
     Some notes: 
      * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication 
      * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly 
      * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this: 
       * Enable inline JS: add 'unsafe-inline' to default-src 
     --> 
     <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> 
     <meta name="format-detection" content="telephone=no"> 
     <meta name="msapplication-tap-highlight" content="no"> 
     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> 
     <link rel="stylesheet" type="text/css" href="css/index.css"> 
     <title>Hello World</title> 
    </head> 
    <body> 
     <div class="app"> 
      <h1>Apache Cordova</h1> 
      <div id="deviceready" class="blink"> 
       <p class="event listening">Connecting to Device</p> 
       <p class="event received">Device is Ready</p> 
      </div> 
     </div> 
     <script type="text/javascript" src="cordova.js"></script> 
     <script type="text/javascript" src="js/index.js"></script> 
    <script type="text/javascript"> 
     document.addEventListener("deviceready", onDeviceReady, false); 
     function onDeviceReady() { 
      window.open = cordova.InAppBrowser.open; 
      var ref = cordova.InAppBrowser.open('http://apache.org', '_self', 'location=yes'); 
     } 
    </script> 
    </body> 
</html> 

とのconfig.xml:

<?xml version='1.0' encoding='utf-8'?> 
<widget id="io.cordova.hellocordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> 
    <name>HelloCordova</name> 
    <description> 
     A sample Apache Cordova application that responds to the deviceready event. 
    </description> 
    <author email="[email protected]" href="http://cordova.io"> 
     Apache Cordova Team 
    </author> 
    <content src="index.html" /> 
    <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:*" /> 
    <platform name="android"> 
     <allow-intent href="market:*" /> 
    </platform> 
    <platform name="ios"> 
     <allow-intent href="itms:*" /> 
     <allow-intent href="itms-apps:*" /> 
    </platform> 
    <engine name="android" spec="~5.2.2" /> 
    <plugin name="cordova-plugin-inappbrowser" spec="~1.5.0" /> 
</widget> 

ので、私はせずに私のアプリを構築しますエラーが発生しましたが、私のアプリで何も表示されない場合は、デバイスが準備完了です。

+0

コルドーバホワイトリストプラグインを追加しましたか? – Gandhi

+0

なぜ文を "ref" varに入れますか?それを削除してコードを挿入してください.InAppBrowser.open( 'http://apache.org'、 '_self'、 'location = yes'); –

+0

共有するとエラーが発生しますか? – johnborges

答えて

3

私は解決策を得ました。あなたの "OnDeviceready"コードをindex.jsファイルで作成された関数に入れました。 ので、

<body> 
     <div class="app"> 
      <h1>Apache Cordova</h1> 
      <div id="deviceready" class="blink"> 
       <p class="event listening">Connecting to Device</p> 
       <p class="event received">Device is Ready</p> 
      </div> 
     </div>   
     <script type="text/javascript" src="js/index.js"></script> 

     <script type="text/javascript" src="cordova.js"></script> 

    </body> 

とindex.jsにindex.htmlの中に次のコードを

を使ってみて、それが「OnDeviceReady」機能を定義するセクションを検索し、

onDeviceReady: function() { 
     app.receivedEvent('deviceready'); 
      window.open = cordova.InAppBrowser.open; 
      cordova.InAppBrowser.open('http://apache.org', '_self', 'location=yes'); 
    }, 
を次のにそれを置き換えるファイル

> 4.4バージョンのエミュレータまたはAndroid搭載端末を使用している場合は、ブラウザのChromeのインスペクタ(chrome:// inspect /#devices)を使用してコンソールのエラーやログをテストしてデバッグできます。

+0

ありがとう、このトリックは私のために働いた – Uahmed