On some phones under Android, there is a physical back button. If you press this button when browsing a web page on your phone, we usually return to the previous page. Is it possible to tie this button to the function of closing the pop-up window on the site? Since it is inconvenient when, instead of closing the window, the page is completely reloaded. Thank!
- Do you need a solution only on Android? Can I offer a solution for all devices? - Dmitry Miroshnichenko
- I am pleased to accept your advice, it's just wonderful) - BigNick174
- Wrote the answer, try it. I did this for quite a long time, and maybe I forgot some step, but I think +/- it will work. - Dmitry Miroshnichenko
|
1 answer
When modally opening a window, use window.history.pushState add a hash to the URL, for example #popup (this simulates switching to another page, but does not reload the page) and create a listener for the URL change event:
window.addEventListener('popstate', function(e){ ... }, false); And in this process, close the popup and delete the handler itself.
|