javascript – Detect smartphone back button


Is there any way to detect when the smartphone 's physical back button is clicked?

I need this to close a modal .

I thought there could be a matching number like on the keyboard and use event.which to detect, but I couldn't find it.


What you can do is use the history API ( ). When you open the modal it would be like entering another page, hence the android's back button and also the browser's will be able to return to the previous state when activated. You don't need to know the code for the button or depend on its existence, as the browser also has one.

Scroll to Top