title: Back button returning to the login page
body: <p>I have a web app that I am developing with phonegap in which the index page is the login page / registration page. </p>
  
  <p>This is fine as this is the first page new users should see when they are not registered to use the app. However this presents 2 issues for me which is when the person logins in and hits the back button it goes back to the login page and I don't want that to happen. Also when the user credentials is stored and they open the app it still goes to the login page for a moment and then goes into the app. </p>
  
  <p>How can I stop this from happening? Do I have to implement a cookie/session type login system?  </p>
  
  <p>My code is below </p>
  
  <p>HTML
      </p>
  
  <pre><code>&lt;div id="home"&gt;
  
      &lt;div id="launcherPage" data-role="page"&gt;
          &lt;!-- I'm just here waiting for deviceReady --&gt;
      &lt;/div&gt;
  
  
      &lt;div id="loginPage" data-role="page"&gt;
  
          &lt;div data-role="header"&gt;
              &lt;h1&gt;CHUNE&lt;/h1&gt;
          &lt;/div&gt;
  
          &lt;div data-role="content"&gt;    
  
              &lt;form id="loginForm"&gt;
              &lt;div data-role="fieldcontain" class="ui-hide-label"&gt;
                  &lt;label for="username"&gt;Username:&lt;/label&gt;
                  &lt;input type="text" name="username" id="username" value="" placeholder="Username" /&gt;
              &lt;/div&gt;
  
              &lt;div data-role="fieldcontain" class="ui-hide-label"&gt;
                  &lt;label for="password"&gt;Password:&lt;/label&gt;
                  &lt;input type="password" name="password" id="password" value="" placeholder="Password" /&gt;
              &lt;/div&gt;
  
              &lt;input type="submit" value="Login" id="submitButton"&gt;
              &lt;/form&gt;
              &lt;div style="text-align: center;"&gt;Or&lt;/div&gt; &lt;!--need to center--&gt;
              &lt;a href="./register.html" data-role="button"&gt;Register&lt;/a&gt;
  
          &lt;/div&gt;
  
          &lt;div data-role="footer"&gt;
              &lt;h4&gt;&amp;copy; KewsPlus&lt;/h4&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>JavaScript</p>
  
  <pre><code> function init() {
  document.addEventListener("deviceready", deviceReady, true);
  delete init;
  </code></pre>
  
  <p>}</p>
  
  <pre><code> function checkPreAuth() {
  console.log("checkPreAuth");
  var form = $("#loginForm");
  if(window.localStorage["username"] != undefined &amp;&amp; window.localStorage["password"] != undefined) {
      $("#username", form).val(window.localStorage["username"]);
      $("#password", form).val(window.localStorage["password"]);
      handleLogin();
  }
  }
  
  function handleLogin() {
  var url = 'http://kewsplus.com/includes/login.php';
  var form = $("#loginForm");    
  //disable the button so we can't resubmit while we wait
  $("#submitButton",form).attr("disabled","disabled");
  var u = $("#username", form).val();
  var p = $("#password", form).val();
  if(u != '' &amp;&amp; p!= '') {
      $.ajax({
          type: "POST",
          url: url,
          data: {username:u,password:p},
          dataType: "jsonp",
          crossDomain: "true",
          jsonp : "onJSONPLoad",
          success: function (data) {
              if (data = 1) {
                  //store
                  window.localStorage["username"] = u;
                  window.localStorage["password"] = p;             
                  $.mobile.changePage("featuredtracks.html");
              }  else {
                  navigator.notification.alert("Your login failed", function() {});
              }
          }
      }); //$.ajax
         $("#submitButton").removeAttr("disabled");
      }
   else {
      navigator.notification.alert("You must enter a username and password", function() {});
      $("#submitButton").removeAttr("disabled");
  }
  return false;
  }
  
  function deviceReady() {
  console.log("deviceReady");
  $("#loginPage").on("pageinit",function() {
      console.log("pageinit run");
      $("#loginForm").on("submit",handleLogin);
      checkPreAuth();
  });
  $.mobile.changePage("#loginPage");
      });
  </code></pre>