Monday, April 16, 2012

Loading a website inside of PhoneGap in Android

I am trying a quick and dirty way to turn my mobile website into an Android app. Using PhoneGap, I created a login page that post its values to my mobile site. However, the login did not seem to have any effect, as I am presented with the login page (now loaded from my website) again.

The problem lies with the fact that the link is opened in a new browser window, rather than within the web view of PhoneGap. There are many questions and answers relating to how to load a website within PhoneGap on StackOverflow, but most solutions didn’t work. Only the following worked for me on the latest version of PhoneGap.

The solution

Open the res\xml\cordova.xml file and add <access origin="example.com" /> to the children of <cordova>. example.com should be replaced by your website address.

No comments: