-1

I'm reading threads for the past 3 hours and came to a realisation that this basic functionality may not exist in late 2017.

I need to catch a user click on the native Back Button when he browse the web on chrome, from his android device.

For example, 1. user goes to www.mysite.com using chrome(The site i'm developing) 2. a modal div pops 3. The user clicks the Back Button on his android device 4. Prevent the window from closing/going back to the previous page. Instead just close the modal.

Very simple request, is it possible?

I also load my webpage on Webviews of third party apps, i guess it should be the same solution.

TBE
  • 1,002
  • 1
  • 11
  • 32

1 Answers1

1

This isn't an Android specific question, it will work the same way with any browser back-button. See the top answer here:

Intercepting call to the back button in my AJAX application: I don't want it to do anything!

Basically, you can't get a Javascript call back from the back button, but you can exploit how the back button is implemented in browsers by using hash fragments to change your URL without the user navigating away. Nevermind, read the second more up-to-date answer there.

amacf
  • 257
  • 2
  • 8