kurumkan
kurumkan

Reputation: 2725

How to detect back button clicked action

Is it possible to detect whether back button was clicked or not using pure java, servlet, jsp. I saw few answers dealing with ajax, javascript etc.

I was trying to detect the action in doGet method of my controller.

But that doesn't work. Noob question.

Upvotes: 0

Views: 1363

Answers (2)

Dropout
Dropout

Reputation: 13866

The event is fired on the client's side, so in order to handle it you need to use a client-side language. If you intercept such event on the client's side, for example with JavaScript, you can notify your back-end to behave in a certain way.

For example with JavaScript you can do

document.getElementById("backButton").addEventListener("click", function(){
    //notify your back-end here
});

of if you mean the browser back button

window.onbeforeunload = function(){
    //check if it was a back-button press using history
    //notify back-end
}

So the answer is no, you can't intercept client-side events with a server-side language.

Upvotes: 2

Dave Newton
Dave Newton

Reputation: 160181

No.

Back button clicks happen on the client side.

There's zero way for the server side to know unless you tell it from the client side.

Upvotes: 2

Related Questions