Block navigation from Second Page to First Page

The script, which actually restricts the user from getting back to the first page from second page, will exists in the first page itself.


The above JavaScript function in the first page 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 (the page 2).

Block refresh operation

We can capture the refresh event using following handler method and then block the operation by returning any message of choice:


Example HTML Pages to practice


Stopping refresh and back button
function preventBack(){window.history.forward();}
setTimeout("preventBack()", 0);

window.onbeforeunload = function() {
return "Do you want to leave this page?";
<a href="Page2.htm">Click Here...</a>


Click the browser back button <br /> or hit the <b>Backspace</b> key.

Do let me know if it works for you.

Disable refresh and back button in browser
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *