3

I am building an application using PhoneGap for Android that can also be uploaded to a server and used as a website.

The problem I'm having is that on the login page I have a JSON call to a php page to check the login credentials and this only works if the user has typed in the full url Including the www., otherwise it returns a json cross-domain error.

I solved this problem using the code below which adds the 'www.' if its not found.

if (document.URL.toLowerCase().indexOf("www.") == -1) {
        var new_url = document.URL.slice(0, 7) + "www." + document.URL.slice(7);
        window.location = new_url;
}

I need to check to see if the user is using the application as a website and call the code above, or if they are using it as an Android app, skip the code above. At the moment the Android app tries to redirect when it hits this code, giving a network error.

Any help is appreciated, Thanks.

SkelDave
  • 1,176
  • 1
  • 9
  • 23
  • 1
    This link will help you, [How to know hand held device][1] [1]: http://stackoverflow.com/a/3540295/1503130 – Prateek Feb 21 '13 at 11:51
  • you can know about the client who made the request using "user-agent" which specifies the http client which made the request.Just search for "user-agent" extracting from Http request. – curious Feb 21 '13 at 11:53

1 Answers1

2

You can do this using navigator object like this:

Wrap your above code inside the if() block,

var ua = navigator.userAgent;
if(!(ua.match(/Android/i))){
   //this code will run only when there is any non-android client.
}
sohel khalifa
  • 5,528
  • 3
  • 32
  • 47