JavaScript method to block the browser return button

  • 2020-05-17 04:47:55
  • OfStack

This article demonstrates how JavaScript blocks the browser's return button. Share with you for your reference. The specific analysis is as follows:

The JS code below can prevent the user from clicking the back button, which is very useful and can be saved by friends who need it.


<SCRIPT type="text/javascript">
  window.history.forward();
  function StopBack() { window.history.forward(); }
</SCRIPT>
</HEAD>
<BODY onload="StopBack();"
  onpageshow="if (event.persisted) StopBack();" onunload="">

I hope this article is helpful for you to design javascript program.


Related articles: