Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call Action class when back button is clicked ?

 
Mickey Smith
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to give a call to my action class in case the browser back button is clicked.

Can i have the solution for the same ?

Thanks in advance
Mickey Smith
 
Philip Shanks
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that some of the Javascript framework libraries provide a way to capture the browser back button -- dojo toolkit comes to mind. I know that dojo allows capturing back clicks as part of their dojo.io.bind class, That may be something you can extract from their source code and re-use for your purposes.

Basically you would have to capture the back button, send a message to the server (your call to the action class), and then let the browser process the back button request. This usually just results in the previous page in history being loaded from cache, which is why the server doesn't know that the back button was used.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no action fired for the back button.

Eric
 
Nathan Hook
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have written a Filter that will add to the response's header so that in theory none of our pages should be cached by any server or browswer. Therefore when a browsers back button is pressed a new request is sent to the server for the page.

 
Philip Shanks
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eric Pascarello:
There is no action fired for the back button.

Eric


True, there is no direct Javascript hook for this (should there be? I imagine it would be heavily abused), but I believe that the dojo packages are using iframe navigation to provide a logical hook. I think this is why their mechanism doesn't work in Safari.

On the other hand, wouldn't the onunload event get fired as a result of a back-button click? Perhaps this could somehow be leveraged to alert the application that the back button *may* have been used. I don't know how this could be made either efficient or effective.
[ February 09, 2007: Message edited by: Philip Shanks ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic