title: Prevent back button from exiting cordova app
body: <p>I've been struggling with this issue where in my cordova app, the back button will exit the app no matter what. I have tried all the solutions I've come across online but haven't had any success.</p>
  
  <p>All the solutions I've tried (example below) have produced the same result.</p>
  
  <pre><code>document.addEventListener("backbutton", onBackKeyDown, false);
  
  function onBackKeyDown() {
      // Handle the back button
  }
  </code></pre>
  
  <p>The code inside my callback executes without issue, but after it executes, it exits the app. I can prevent the exit by including a <code>ReferenceError</code> in my function, for example</p>
  
  <pre><code>console.log(undefinedVar);
  </code></pre>
  
  <p>But this obviously doesn't seem like best practice.</p>
  
  <p>The other solutions I've tried include using <code>event.preventDefault()</code> from the callback and ionic's <code>registerBackButtonAction</code> function.</p>
  
  <p>Any suggestions would be greatly appreciated.</p>