title: Javascript - Check if Web App or Android App
body: <p>I am building an application using PhoneGap for Android that can also be uploaded to a server and used as a website. </p>
  
  <p>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 <strong>Including</strong> the www., otherwise it returns a json cross-domain error. </p>
  
  <p>I solved this problem using the code below which adds the 'www.' if its not found.</p>
  
  <pre><code>if (document.URL.toLowerCase().indexOf("www.") == -1) {
          var new_url = document.URL.slice(0, 7) + "www." + document.URL.slice(7);
          window.location = new_url;
  }
  </code></pre>
  
  <p>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. </p>
  
  <p>Any help is appreciated, Thanks.</p>