I have an requirement where i want to call a java method when i click the browser forward or backward button.
Previously I implement the same by using Jquery and JavaScript,found easy to implement the same.Here is the link
But now my requirement is to do the same by executing a java method.And in this java method i will execute my own Business requirement.
My previous JavaScript code to implement the same is attached below
window.onbeforeunload = function (e) {
........
......
}
My previous JQuery code to implement the same is attached below
window.userInteractionTimeout = null;
window.userInteractionInHTMLArea = false;
window.onBrowserHistoryButtonClicked = null; // This will be your event handler for browser navigation buttons clicked
$(document).ready(function () {
$(document).mousedown(function () {
clearTimeout(window.userInteractionTimeout);
window.userInteractionInHTMLArea = true;
window.userInteractionTimeout = setTimeout(function () {
window.userInteractionInHTMLArea = false;
}, 500);
});
$(document).keydown(function () {
clearTimeout(window.userInteractionTimeout);
window.userInteractionInHTMLArea = true;
window.userInteractionTimeout = setTimeout(function () {
window.userInteractionInHTMLArea = false;
}, 500);
});
if (window.history && window.history.pushState) {
$(window).on('popstate', function () {
if (!window.userInteractionInHTMLArea) {
// alert('Browser Back or Forward button was pressed.');
}
if(window.onBrowserHistoryButtonClicked ){
window.onBrowserHistoryButtonClicked ();
}
});
}
});
I am using the following java version
- Java 1.8
- Eclipse IDE
- Maven
Any help is highly appreciated, all the best in advance,Good Luck!!!