Skip to content Skip to sidebar Skip to footer

How To Disable Back Button Of Browser Using Javascript

I want to disable the back buttons in the browser using JavaScript. Can any one help me how to do that?

Solution 1:

Read here for several options to disable the back button.

BUT: The question makes me feel like you're trying to solve the wrong problem.

The back button is something that the user expects to work. If you disable it, you would break the browser (from the user perspective): Something that works everywhere else doesn't work on your page. Users would hate your page and try to avoid it. If they can't avoid the page, they would hate it even more.

So what are your options:

  1. You can get events when the user uses the button. GWT, for example, saves the internal state of the application in virtual history events. So the user can use the back button like Undo in a real application.

  2. Avoid creating history events for your page. Make sure the URL in the title bar never changes. Save all changes on your server. For the user, the page/application will feel like one page. When he returns next time, restore the last state from the database on your server.

    This way, the user can use the back button to leave your page as he is used to but he still won't loose any work.

  3. A mix of the two. For example stack overflow allows you to move between the pages using links and the back button. If you start to edit something on a page, you get a warning when you click on the back button.

Solution 2:

functionnoBack() {
    window.history.forward();
} 

Solution 3:

Simplelogic: move forward when click back button
 ---------------------------------------------------- 

functionpreventBack() {
    window.history.forward();
}
 window.onunload = function() {
    null;
};
setTimeout("preventBack()", 0);


Keepthis js code in your page it works.

Solution 4:

Simply open your page in a new tab using javascript like this

<scripttype="text/javascript"language="Javascript">window.open('yourpage.html');</script>

set this code to your previous page and this will open your page in a new tab and there will be no back button available.

Post a Comment for "How To Disable Back Button Of Browser Using Javascript"