0

I have a office add-in which I enabled for mobile too. After viewing multiple tabs in the add-in, Android back button is actually coming out of the add-in instead of going to previous view. This is expected since I don't change the URL for each page(I do ajax).

I got a review comment from Microsoft reviewer asking I should handle navigation in a way that, it should go back to previous view.

I believe Android back button is more like a hardware event. Is that is even possible to identify that back button event?

Any help would be greatly appreciated.

Siva Kumar J
  • 165
  • 1
  • 10

1 Answers1

0

After the Outlook add-in is loaded, the Android back button press is the same as pressing the back button in your web browser. The outlook add-in runs inside an embedded Android Webview which supports the popstate event. You can set up an event listener for the popstate event:

window.addEventListener('popstate', () => {
    this.onBackButtonPressed();
}, false);

The popstate event only fires if there are items in the history stack. So to make sure that the history is not empty you can push an item when your add-in is loading:

if (window.history && window.history.pushState) {
    window.history.pushState({}, '');
}

Note that the Office JS API sets the history.pushState and history.replaceState functions to null (Github issue). In order to call pushState after the Office JS API has loaded you need to either use a polyfill or restore the pushState function.

01001
  • 3
  • 3