How do I disable Android Back button on one page and change to exit button on every other page

How do I disable Android Back button on one page and change to exit button on every other page

Hello community,

I am developing an Android application using Phonegap that interacts with my Drupal site. I have re-assigned the Android "Back" button to prompt the user to log off from the Drupal server however, I just want it disabled on the login page (for obvious reasons). I can get it to work but only until the user logs out then once on the login page the button remains re-assigned as a logoff button. Here's the code I have so far:

  1. <head>
  2.          <script>
  3.         /* Wait until device is ready to re-assign Back button */
  4.         document.addEventListener("deviceready", onDeviceReady, false);
  5.         function onDeviceReady() {
  6.             document.addEventListener("backbutton", onBackKeyPress, false);
  7.         }
  8.         function onBackKeyPress() {
  9.             /* If the current page is the login page, disable the button completely (aka do nothing) */
  10.             if ($.mobile.activePage.attr('id') == 'login_page') {
  11.             }

  12.             /* Else, execute log off code */
  13.             else {
  14.                 if (confirm("Are you sure you want to logout?")) {
  15.                     /* Here is where my AJAX code for logging off goes */
  16.                 }
  17.                 else {
  18.                     return false;
  19.                 }
  20.             }
  21.         }
  22.         </script>
  23. </head>

The problem is that the Back button doesn't get re-assigned. I cannot figure out a way to re-run the above code when the user logs out and ends up back on the login page.

If anybody is willing to provide a solution for this I will be very grateful!