Sorry if duplicate, but I don't understand how I can use the basic approach in my case. I need to hide some div, when user presses back button in browser. That is all what I need. The page must not to be reloaded. I tried this way:
window.onpopstate = function (event) { event.preventDefault(); alert("Back button pressed"); myDiv.style.display = 'none'; } But this doesn't work at all. Even alert doesn't fire. And the browser goes back as always.
How to make it work? First of all this must works in mobile browsers. Will the using of window.location.hash trigger page reloading or not?