title: Handling android backbutton in OnsenUI + Cordova
body: <p>I'm aware of the following questions that relate to this, but do not solve the problem I face.</p>
  <blockquote>
  <p><a href="https://stackoverflow.com/questions/33513659/onsen-uicontroll-android-backbutton-routes">Onsen uI:Controll android backbutton routes</a></p>
  <p><a href="https://stackoverflow.com/questions/31869577/onsen-uidisable-device-backbutton-in-android-didnt-work">Onsen ui:Disable device backbutton in android didnt work</a></p>
  </blockquote>
  <p>Here is my code in index.html:</p>
  <pre><code>ons.ready(function () {
          ons.disableDeviceBackButtonHandler();
          appnavigator.getDeviceBackButtonHandler().disable();
          
          window.document.addEventListener('backbutton', function (event) {
              if (appnavigator.getPages().length &gt; 1) {
                  event.preventDefault();
                  appnavigator.popPage();
                  console.log('Popped a page and now we have', appnavigator.getPages().length, 'pages');
              } else {
                  console.log('No more pages on stack, quitting...');
                  navigator.app.exitApp();
              }
          }, false);
      });
  </code></pre>
  <p>I have <code>&lt;ons-navigator id=&quot;navigator&quot; var=&quot;appnavigator&quot;&gt;</code> in the body.</p>
  <p>This pops a page, and then quits the application. Why is that? I'm using Onsen UI v 1.3.14 and Cordova 5.3.3.</p>