This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes To Disable Back button in all the browsers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "To Disable Back button in all the browsers" Watch "To Disable Back button in all the browsers" New topic

To Disable Back button in all the browsers

Dev Anand
Ranch Hand

Joined: Aug 30, 2009
Posts: 41
Currently i'm using the following code to disable the back button in my jsp page, but it works fine only in IE.

<script type="text/javascript">

Can anyone give the code to disable the back button in all browsers like opers, firefox, chrome etc..
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 39569
Please be sure to heed

Which brings up the question: why do you want to do this?

Ping & DNS - updated with new look and Ping home screen widget
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 784

Thanks Ulf
The link is very usefull.

SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Sean Clark

Joined: Jul 15, 2009
Posts: 377


whilst you cannot disable the browser back buttons, you can add onbeforeunload event which will allow you to add functionality before the page is left.

I used this to add a confirmation box to notify users that leaving the page would lose any unsaved changes.

Note though that you cannot attach this to just the back button, and whenever the user tries to leave the page via a link/forward/back/reload, they would get the message.


I love this place!
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15376
guessing you have a typo in your code above since histroy is misspelled.

If you use proper headers and posts, you can expire a page when the back button is pressed.

I agree. Here's the link:
subject: To Disable Back button in all the browsers
Similar Threads
Disable the functionality of the back button in all browsers.
Back button issue
Disabling the Back button of the browser
Disable back button of browser using javascript
Back Button & Mouse Risk click