14

I want to be able to link to a webpage inside the phonegap webview that loads an external webpage inside the same phonegap webview. If I do this, it loads inside the webview:

public class App extends DroidGap {
   @Override
   public void onCreate (Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      super.loadUrl("http://google.com");
   }
}

However, I want to have an internal page launched first, with a link to the external page, so I do this:

public class App extends DroidGap {
   @Override
   public void onCreate (Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      super.loadUrl("file:///android_asset/www/index.html");
   }
}

and I have a link:

<a href="#" onclick="navigator.app.loadUrl('http://google.com')">Google</a>

but this link launches google outside the app, in the web browser, instead of in the phonegap webview. What can I do to make sure the link to the external page is launched inside the app's phonegap webview?

xdumaine
  • 10,096
  • 6
  • 62
  • 103

3 Answers3

18

Ahhh.. Found the answer on this question. I had to add

<access origin="www.google.com"/>

to the phonegap.xml file.

Community
  • 1
  • 1
xdumaine
  • 10,096
  • 6
  • 62
  • 103
10

This seems to have changed, and access origin seems to have no effect. If you're using the cordova whitelist plugin, as seems to be standard. You need to use allow-navigation in your config.xml file. Without this it will open your web browser.

<plugin name="cordova-plugin-whitelist" version="1"/>
<allow-navigation href="https://google.com/*" />

Then you can use window.location = 'https://google.com' to move to another webpage within your JS.

dngrmice
  • 101
  • 1
  • 3
3

In the latest phonegab (1.7) in Cordova.plist there is a Key: OpenAllWhitelistURLsInWebView set this to YES.

tapmonkey
  • 141
  • 2
  • 9