title: Phonegap backbutton event, detect first page in history?
body: <p>Adding a <code>backbutton</code> event listener to my Phonegap 2.0 mobile app prevents the user from exiting using the back key.</p>
  
  <p>Before adding the event listener this was working: if the user visited N pages and clicked back N+1 times, the app would close (or go in the background for android 4.0 or higher).</p>
  
  <p>Please see my code bellow.</p>
  
  <pre><code>document.addEventListener("backbutton", function(){
      if (window.history.length == 0) { // this does not work
          function quitApp(){
              navigator.app.exitApp();
          }
          navigator.notification.confirm(
              "Are you sure you want to quit?",
              quitApp,
              'App Title',
              'Cancel,Ok');
          return;
      }
      if (typeof(window.activePage.onBack) === 'function') {
          window.activePage.onBack();
      } else {
          window.history.back();          
      }
  }, false);
  </code></pre>
  
  <p>Any idea how i can achieve this: allow the user to exit using the back button while keeping my event listener?</p>
  
  <p>Thanks!</p>