Back button event not working

  • 1
  • Problem
  • Updated 4 years ago
Hi,

I will use below code for exit app but event not working.

<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady(){
alert();
document.addEventListener("backbutton", function(e){
if($.mobile.activePage.is('#deviceready')){
e.preventDefault();
navigator.app.exitApp();
}
else {
navigator.app.backHistory()
}
}, false);
}
</script>


Please help me
Photo of Amol Rajput

Amol Rajput

  • 13 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 1
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
How did you determine that the backbutton event is not fired?
Have you checked the object type value for 'navigator.app' and both its methods you are using?
Photo of Amol Rajput

Amol Rajput

  • 13 Posts
  • 0 Reply Likes
Can you please elaborate your above answer
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
1. You wrote
Back button event not working
And my question is: HOW did you determine that the event was 'not working'??
- Did you observe that the event was indeed not fired?
- Or did you merely observe that "this whole script did nothing"?
- Or was there some other determination that made you think that the "event does not work"?

2. Have you made certain that, within this script, the object 'navigator.app' was instantiated and the methods exitApp and backHistory were defined as 'function' type?