ppowell777
Coder
I am trying to push a URL onto a browser history to "prevent" the back button from going back to the previous page. Currently if the user clicks the back button, they simply go back to the Feedback page with the Submit button in a disabled state, which, while it prevents the user from flooding Feedback this way, it's not exactly the way I envisioned doing browser-side protection of flooding. I know that the back button can never be disabled on a browser, but I learned (or thought I learned) how to push onto the browser history using both
Does anyone have any ideas? Thanks
history.pushState()
and window.addEventListener('popstate', function() {})
, and so wrote this, which, sadly, does absolutely nothing:
Code:
/**
* Prevent the back browser button from practically working by pushing onto the browser history. Click
* <a
* href="https://stackoverflow.com/questions/19558038/how-to-restrict-the-user-not-go-to-previous-pages-by-clicking-the-browsers-back">
* here </>
* for more informtion
*/
$(document).ready(() => {
const href = document.location.href.substring(0, document.location.href.lastIndexOf('/'));
if (window.history != undefined && window.history != null && history.pushState != undefined && history.pushState != null) {
window.addEventListener('load', () => {
history.pushState({}, '', href + '/error.html?');
window.addEventListener('popstate', () => {
history.pushState({}, '', href + '/error.html#');
});
});
}
});
Does anyone have any ideas? Thanks