RSS
 

Posts Tagged ‘cordova’

PhoneGap – Detect if the application runs on mobile or browser using JavaScript before the “deviceready” and document “ready” events are triggered

05 Nov

I spent hours to find out how to do it. And believe me or not, I found nothing on the whole internet about how to solve it.

Actually there is a simple way to do that after the event “deviceready” has been triggered (as described on the PhoneGap’s API Docs), it is simple as:

1
2
3
4
5
6
7
document.addEventListener("deviceready", function(e){
if ( device ) {
alert("Running on PhoneGap!");
} else {
alert("Running NOT on PhoneGap!");
}
}, false);

Read the rest of this entry »