• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Disabling the Back button of the browser

 
Naik Priyanks
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How can I disable the back button of the browser?
I want to stay on the same page when the user clicks the back button without doing any action.
Any help would be appreciated.
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTML/Javascript is more apt for this thread, I guess.

Simple answer: You can't.

There are ways to disable the back button (by removing the tool bar etc), but there are lot of other ways using which the user can navigate to the previous page (using Backspace button, right click and click 'Back' etc)

The proper way to solve the problem is to design your system in a way to manage such behaviours (back, forward, refresh etc).
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

How can I disable the back button of the browser?


You cannot disable back browser button from server side code
 
Ajith George
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can disable back button of your browser by including the following javascript on that page.

or

This will work only on IE. i think so. But this is not the correct way of doing as client may use other browsers also.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ajith George:
You can disable back button of your browser by including the following javascript on that page.

I tried this in IE and it causes the page to automatically send you back one page, which is close to the opposite of "disabling the back button"! Are you sure this is what you meant?
 
Ajith George
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry there was a mistake. The correct way of doing is


Try this !
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ajith George:
Sorry there was a mistake. The correct way of doing is



That doesn't seem to work either. Try it:

Are you sure that you know how to do this?
 
Ajith George
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's working for me. This is code for test2.jsp
And this is code for test3.jsp

Both jsp's have almost same code and both have links between them.
When i reached test3.jsp from test2.jsp, ican't return back using my back button. Vice versa too it's working. Try this !
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! I understand now Here's a simpler example, because your example with links going between two pages hides the hack:

When you visit page 1 the back key is functional (this is why I thought history.forward isn't working). Then you follow the link to page two, and the back button is still *enabled* but when you click on it *that's* when the forward method successfully fires and sends you back to page 2. Maybe I'm hoping for too much, but is there a solution that truly *disables* the back button?
[ March 29, 2006: Message edited by: Jeff Albertson ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to HTML.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not disable the back button, you can not remove it, you can not defeat my button on my mouse or combinations on the page.

What if JavaScript is disabled, and all of that other stuff.

As I always tell people: Build your application around the browser!

Eric
 
Naik Priyanks
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for ur valueable input.
 
Vikram Waikar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
with all due respect to good design decisions and best practices , isn't there a simple hack for this ?
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No doubt there is a simple hack. But there is not a solution to the problem that "disabling the back button" is supposed to solve.

Let's suppose you manage to disable the back button on my browser. When I find you have done that I mutter something about your mother. Then I right-click on the link, and open the new page in a separate tab. Then when I want to go back to the page I just came from, it's right there in the first tab. Not only is your problem not solved but you provided me with an annoying interface as well.

At this point the true fanatic will try to prevent me from right-clicking on links. And to prevent me from using that drop-down thing next to the back button which lets me go back to any of the last few pages I viewed. And to prevent me from using the "Back" option on my browser's menu. The professional will get a life and write their server to work properly when these browser features are used.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And doing silly things like disabling browser buttons and the right-click menu will bring you fame:

http://www.webpagesthatsuck.com/worst-web-design-featured-on-web-pages-that-suck-in-2005.html

But probably not the type you are wanting.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic