1

How do I open external websites inside the webview used by phonegap. If I'm using

window.location.href = "www.example.com"

It will open the browser and load the website instead.

I found https://github.com/phonegap/phonegap-plugins/tree/master/Android/ChildBrowser but this will open a modal with the website.

1 Answer 1

3

In your PhoneGap.plist add under the ExternalHosts key: *.example.com. It's in fact a white list to prevent your application going to non-authorized url, otherwise it will open in the webbrowser which is kind of a sandbox environment.

Anyway I don't think it will work, if you leave the PhoneGap structure by going to an other url, in addition to the whitelist, you should use an iframe to handle external links.

EDIT: for Android open your config.xml file and add the following:

  • To allow access to every domains: <access origin="*" />
  • To a specific domain: <access origin="http://phonegap.com" subdomains="true" />

You can also check the documentation of this file.

3
  • Didn't mention that I'm experiencing this problem on android, so I don't have a .plis file
    – LHolleman
    Apr 20, 2012 at 12:40
  • Ok so on android, you should be able to use iframe directly since it is allowed by default, if it doesn't work then in your config.xml file add the following: <access origin="*" />
    – Tronix117
    Apr 20, 2012 at 12:47
  • The Android equivalent white-list is the config.xml file that you should have in the res/xml folder.
    – codemonkey
    Apr 20, 2012 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.