aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to call Action class when back button is clicked ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to call Action class when back button is clicked ?" Watch "How to call Action class when back button is clicked ?" New topic
Author

How to call Action class when back button is clicked ?

Mickey Smith
Ranch Hand

Joined: Jun 26, 2006
Posts: 30
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

Joined: Oct 15, 2002
Posts: 189
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.


Philip Shanks, SCJP - Castro Valley, CA
My boss never outsources or has lay-offs, and He's always hiring. I work for Jesus! Prepare your resume!
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is no action fired for the back button.

Eric
Nathan Hook
Ranch Hand

Joined: Jan 10, 2005
Posts: 81
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

Joined: Oct 15, 2002
Posts: 189
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 ]
 
Don't get me started about those stupid light bulbs.
 
subject: How to call Action class when back button is clicked ?