Disable Browser Back Button Using JavaScript

Updated on     Kisan Patel

Disable Browser Back Button Using JavaScript

Just add the below code in the head section of the html page.

<script type="text/javascript">
     window.onunload=function(){
       window.history.forward();
     };
</script>

The above JavaScript code uses the history of the browser and forces it to navigate forward instead of going to the previous page. Therefore, every time the user clicks the back button or hits the backspace key, it will result in the Browser navigating or pushing the user forward and showing the same page.

Image Credit: laptopmag.com


JavaScript

Leave a Reply