• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Back Button detection with Servlet

 
Kelley Koszegi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Looking through this group and others, I see that disabling the browser back button is not 100% possible. But is it possible for a servlet to somehow 'detect' that the back button was pressed? Are there any tricks to do this?
Just for background: the application I am working on will fail sometimes when using the back button because information is taken both from a link on the page and the session. When using the back button, the session data will become outdated and may not be compatible with the link parameters of the current page.
Any suggestions would be appreciated. TIA!
--Kkoszegi
 
Brian Blesbok
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use:
history.go(1);
in the header of each and every servlet page - include it in a js file if you want... that way, when a user presses the back button, on trying to load the provious page, the browser goes forward one ie: stays on the current page.
In IE this works sweet, and there is no page flicker really -but NutScrape has a bit of a flicker - but both work.
This is the only way I have found of disabling the back.
Another way, is to code your app so that it handles the situation where someone has pressed the back button. always code for the worst case scenario -if a user can break it, they will - and complain they will also!!
cheers
 
Kelley Koszegi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Thanks for your reply, Brian. Things have changed a little and disabling the back button is not a possibility.
Like I said before, I am interested in finding out how the servlet could detect that the back button was pressed. Does anyone have an idea as to how I could do that?
Thanks,
--KKoszegi
 
Kareem Gad
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To my knowledge its not actually possible to have some browser listener and deal with the events happening on the browser .. back or no back ..
its all client side.
Servlets are server side remember ?

------------------
KaReEm
 
Steve Snodgrass
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We use javascript and hidden fields to detect the condition where a page is loaded from the browser cache as opposed to the server. If it is we pop up an alert informing the user that they should hit refresh to get the latest data or unexpected results may occur. Alternatively you could post a form to the servlet upon this condition so it is aware of the situation and handles it.
Our app has never been tested with Netscape so I am not sure if this would work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic