Handling android hardware back button in mobile web?

I’m using Ionic 1.2.1 to create an app that works both as an Android/iOS Cordova app and as a mobile website. Kudos to the Ionic team for doing such a great job making that possible! However, I’m trying to handle the Android hardware back button and I have code in a controller that works great in the mobile app, but doesn’t work at all in Chrome for Android. This is the basic code:

document.addEventListener(‘backbutton’, function() {
// code here

The code inside the listener function doesn’t execute at all in Chrome. If I wrap all of this in an event listener for the ‘deviceready’ event, that also doesn’t execute at all. It seems like these two events just don’t happen in Chrome (though they do in the Cordova app).

Does anyone know of a way to handle the hardware back button in plain old Chrome?

So did you find the solution to this? I’m am pretty much screwed due to this.

UPDATE: I got this to work. I removed the earlier binding to the Soft and Hard back buttons and instead listened to the “$stateChangeStart” event on the $rootScope. Thus by using, event.preventDefault(); I was able to prevent it from transitioning back on the mobile web as well as android or iOS. :smiley: