Detect Smartphone back button

Asked

Viewed 173 times

3

Is there any way to detect when the physical button comes back from smartphone is clicked?

I need it to close one modal.

I thought there might be a matching number like on the keyboard and use the event.which to detect, but not found.

  • I think this is very relative, because iPhones have no back button, this is more crazy.

  • Yes, but on android would have some way to do this?

1 answer

0

What you can do is use the history API (https://developer.mozilla.org/en-US/docs/Web/API/History_API). When you open the modal would be like entering another page, then the back button of android and also the browser will be able to return to the previous state when triggered. You don’t need to know the button code or depend on its existence, since the browser also has a.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.