Reputation: 1101
I'm developing a small app mainly for self education purposes and I've decided to code the app in HTML / JS and use phonegap to convert it to a "native" app.
This is all working perfectly fine and I've successfully installed a HelloWorld app on my phone.
Besides as a native app I also want to make my project available on the internet using a browser. So that my users can either visit the url in their browser or download and install the app.
Therefore my question:
Is it possible to use Phonegap and its API online on a standard website? Meaning that I can use phonegaps functions to access the geolocation for example.
Otherwise I would have to change my javascript code and not use phonegap on the website.
Upvotes: 0
Views: 430
Reputation: 18870
The PhoneGap/Cordova API ties in with the functionality available on the device and therefore is not available via a "normal" website.
However, with the example you used, Geolocation is NOT PhoneGap/Cordova specific, it's a W3C specification and available on most modern browsers, so you can use that one.
Upvotes: 1
Reputation: 4847
Sorry, I don't believe that is going to work. What you could try instead is to wrap any calls that you make to phonegap with a check to see if you are on a phone or in a browser and switch based on that. This will force you to decouple your code from phonegap & create good boundaries.
I used this, which isn't perfect (especially if a users vists your site in their mobile browser), but it's a start:
//jquery - for working in browser
$(document).ready(function() {
if (!navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/)) {
console.log("we are in a browser");
}
});
//phonegap - for working in app
function onDeviceReady() {
console.log("we are an app");
}
function onBodyLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
Upvotes: 1