Reputation: 391
I want to call a method from a class (jsf bean) when user leave the page by clinking back button of browser. I tried to use window.onbeforeunload, however it works for every situation. For example when user redirected with a link or button. How can I make it just for back action?
Upvotes: 0
Views: 80
Reputation: 435
What you need is the history API.
https://developer.mozilla.org/en-US/docs/Web/API/History_API
window.onpopstate = function(event) {
console.log("location: " + document.location + ", state: " + JSON.stringify(event.state));
};
Upvotes: 2