Search code examples
javascriptvue-routerhtml5-history

Is it possible to detect hardware back button click event on android device by js?


Can I detect click event when user press hardware back button (button on mobile context menu) using js?

For example, I have two pages:

  • Login
  • Homepage

The homepage has a popup window, currently, when the popup is showing and then user press the back button, browser will be back to login page. But I just want browser close the popup instead of go back to login page in this case.

Is it possible to detect it?

Edit: This question is about the hardware back button on mobile device (android), not the browser back button.


Solution

  • This is the correct anwser that I got from @Igor:

    you should just do $router.push({ query: { popup: true } } on popup show and browser back button will return you back to home route without page reloading