Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes HTML, CSS and JavaScript and the fly likes Disabling Back Button in a browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Disabling Back Button in a browser" Watch "Disabling Back Button in a browser" New topic

Disabling Back Button in a browser

Raja Rama

Joined: Dec 19, 2002
Posts: 2
Hi all,
I want to disable the back button in my browser. I have included the following in my code.
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
But it does not help me. Kindly anyone let me know how I achieve both the Back button in the browser and also the right click.
Thank you in advance.
Dave Comeau

Joined: Jun 14, 2002
Posts: 27
What is your goal in removing browser functionality?
There are lots of tricks and hacks to "disable" the back button, try a search on google.
None of them are elegant or user friendly.
I would suggest you re-think the structure of the page you are trying to prevent people from returning to. Sessions seem to work well for me.
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

also, if you search for "disable back" in this forum -- you'll find about 2 dozen posts on the topic. Enjoy!
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
right click is useless!! a right click script also blocks users that have their mouse set up for left handed......
If you are trying to protect not do it...useless.....javascript..html...opensource...not microsoft.....
Steven Lyner

Joined: Jul 02, 2001
Posts: 10
I had the same problem and I found this code on the net.
I put it between the <head> and </head> tags of the page I wanted not to be displayed.
boyet silverio
Ranch Hand

Joined: Aug 28, 2002
Posts: 173
that's a nice share Steven, I could also use that.
I agree. Here's the link:
subject: Disabling Back Button in a browser
It's not a secret anymore!