Search code examples
ioscordovaphonegap-pluginscordova-plugins

Phonegap inappbrowser not working


I had a simple test on plugin cordova-plugin-inappbrowser and it just doesn't work, please help. What I did: 1. phonegap create phonegap-default
2. phonegap plugin add cordova-plugin-inappbrowser --save
3. add this line to www/index.html at the bottom inside "app" div:

<a href="var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');"><h1>Test</h1></a>

The index.html is like following:

<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Hello World</title>
</head>
<body>
    <div class="app">
        <h1>PhoneGap</h1>
        <div id="deviceready" class="blink">
            <p class="event listening">Connecting to Device</p>
            <p class="event received">Device is Ready</p>
        </div>
    <a href="var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');"><h1>Test</h1></a>
    </div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>
</body>

  1. phonegap serve
  2. open phonegap develop app (in iOS 9.2.1), connect to phonegap server then touch the Test link. Nothing happened.

My Phonegap version is 5.4.1. Thanks in advance.


Solution

  • I think you should add:

    <access origin="http://apache.org" subdomains="true" /> 
    

    in the config.xml Maybe it is also nessessary to add

    <feature name="InAppBrowser">
        <param name="ios-package" value="CDVInAppBrowser" />
    </feature>
    

    For further Information go to: https://cordova.apache.org/docs/en/3.0.0/cordova/inappbrowser/inappbrowser.html

    For using this plugin with Android you should also add the cordova-plugin-whitelist plugin:

    https://github.com/apache/cordova-plugin-whitelist