Back
Remove back button press behaviour of browsers
October 31, 2015

Remove back button press behaviour of browsers

Posted on October 31, 2015  • 1 minute  •JQuery

In most of online examination, developer uses concept of remove browser back button press behaviour, after implementing this user unable to press browser back button to go previous page.

This can be acheived using Jquery:

window.location.hash="no-back-button";
window.location.hash="Again-No-back-button";//again because google chrome don't insert first hash into history
window.onhashchange=function(){
  window.location.hash="";
  history.replaceState('', document.title, window.location.pathname);
}

// remove fragment as much as it can go without adding an entry in browser history:
window.location.replace("#");

// slice off the remaining '#' in HTML5:    
if (typeof window.history.replaceState == 'function') {
  history.replaceState({}, '', window.location.href.slice(0, -1));
}
Follow me

I work on web development using Javascript.