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?
You can think of the web view as a tab in a browser. When you compile a Cordova application, it doesn't actually take your HTML, CSS, and JavaScript code and automagically converts it into native code, specific to each platform. Cordova acts as a container for the app that you write using web technologies.
The InAppBrowser is a web browser view that displays when calling [window. open](window. open. html)() , or when opening a link formed as <a target="_blank"> . var ref = window.
Ahhh.. Found the answer on this question. I had to add
<access origin="www.google.com"/>
to the phonegap.xml
file.
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.
In the latest phonegab (1.7) in Cordova.plist there is a Key: OpenAllWhitelistURLsInWebView set this to YES.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With