
In some cases, we may want to prevent the page from going back in the browser. Thus, we may have prevented the back button from functioning on mobile or desktop devices.
You can use the following javascript code when you do not want the back button to function.
history.pushState(null, null, location.href); history.back(); history.forward(); window.onpopstate = function () { history.go(1); }; function preventBack() { window.history.forward(); } setTimeout("preventBack()", 0); window.onunload = function () { null }; preventBack(); window.onload = preventBack(); window.onpageshow = function(evt) { if (evt.persisted) preventBack() }
I hope it works out for you.