Tarak
Tarak

Reputation: 1212

Disable device back button click in OpenUI5?

How can i disable android device back button click in Phonegap OpenUI5 application? Tried this but didn't work:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() 
{
     document.addEventListener("backbutton", function (e) {
         e.preventDefault();
     }, false );
}

Upvotes: 2

Views: 1586

Answers (1)

Jonathan Benn
Jonathan Benn

Reputation: 3569

Generally speaking, browsers don't allow you to disable the back button. This is for security/usability reasons so that you can't trap the user on your webpage. Hence, you need to think twice before doing it to make sure that you're actually trying to help your user.

That having been said, there are techniques described here that might work for you.

I would personally suggest that you do the right thing and rather than disable the back button you simply handle the event and do the appropriate clean up in your app.

In SAPUI5 you can use jQuery to listen to navigation events:

// event fired when the user changes the URL, e.g. forward or back navigation
// you need to implement the handleNavigate handler
$(window).on("navigate", handleNavigate)

// event fired when the user tries to close the browser or reload the page
// you need to implement the handleBeforeUnload handler
$(window).on('beforeunload', handleBeforeUnload);

Upvotes: 1

Related Questions