Advertisement
JamieMontreal

20140309 - My PhoneGap Testing Code for the backbutton

Mar 9th, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // **** PHONEGAP SECTION ****
  2.  
  3. // Wait for device API libraries to load
  4.  
  5. setTimeout(onLoad, 10000);  // xx seconds into use of the app, start up the PhoneGap processes.  Note that this is not the
  6.                             // optimal way, but it'll do for now (doesn't go on at earliest ready moment, nor does it account for browsers)
  7.  
  8. //  Reference:  http://docs.phonegap.com/en/3.4.0/cordova_events_events.md.html#deviceready
  9. function onLoad() {
  10.     document.addEventListener("deviceready", onDeviceReady, false);  // call onDeviceReady once PhoneGap is ready
  11. }
  12.  
  13.  
  14. // device APIs are available
  15. //
  16. function onDeviceReady() {
  17.     // Now safe to use device APIs via Phonegap
  18.     alert("Phonegap is successfully up and listening...");  //  <--- success
  19.     document.addEventListener("backbutton", onBackKeyDown, false);
  20.     document.addEventListener("menubutton", onMenuKeyDown, false);  
  21. }
  22.  
  23.  
  24. function onBackKeyDown() {
  25.     alert("Someone hit the backbutton...");  //  <--- this doesn't work, yet...
  26. }  // end of onBackKeyDown function
  27.  
  28.  
  29. function onMenuKeyDown() {
  30.     alert("Someone hit the menubutton...");  //  <--- somehow this works.  Go figure.
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement