wood burning stoves*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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
Author

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">
histroy.forward(1);
</script>

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

Joined: Mar 22, 2005
Posts: 41591
    
  55
Please be sure to heed http://faq.javaranch.com/java/InterfaceDesignersRule1.

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


Ping & DNS - my free Android networking tools app
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787

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
Rancher

Joined: Jul 15, 2009
Posts: 377

hey,

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.

Sean


I love this place!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To Disable Back button in all the browsers