I am using JSF 2.2 with PrimeFaces on WildFly 17 application server and want to disable the back-button of a browser.
I have already tried with:
https://stackoverflow.com/a/20321530/1925356
Avoid back button on JSF web application
https://stackoverflow.com/a/10305799/1925356
but I was not able to prevent the functioning of the browser's back-button. To be more precise, I have tried this in my xhtml template:
<h:body>
<script>
const O_BACK_BUTON = "o-back-button";
const NO_BACK_BUTON = "n" + O_BACK_BUTON;
const CROME_NO_BACK_BUTON = "Again-N" + O_BACK_BUTON;
jQuery(document).ready(function() {
jQuery(document).ready(function() {
window.location.hash = NO_BACK_BUTON;
window.location.hash = CROME_NO_BACK_BUTON; // Again because google chrome doesn't insert first hash into history
window.addEventListener ? window.addEventListener('hashchange', disableHash) : window.attachEvent('hashchange', disableHash);
});
});
function disableHash() {
window.location.hash = NO_BACK_BUTON;
}
</script>
But it does not work. (Almost) the same code works ins struts 1.0
What am I doing wrong?