Skip to content

Instantly share code, notes, and snippets.

@FranciscoGutierrez
Last active February 6, 2018 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FranciscoGutierrez/ae96f3af90f8f6fd6d8e923212a334da to your computer and use it in GitHub Desktop.
Save FranciscoGutierrez/ae96f3af90f8f6fd6d8e923212a334da to your computer and use it in GitHub Desktop.
a simple script to prevent user to going back in the browser.
jQuery(document).ready(function($) {
if (window.history && window.history.pushState) {
$(window).on('popstate', function() {
var hashLocation = location.hash;
var hashSplit = hashLocation.split("#!/");
var hashName = hashSplit[1];
if (hashName !== '') {
var hash = window.location.hash;
if (hash === '') {
alert('Warning, if you press back button, you will lose your progress...');
}
}
});
window.history.pushState('forward', null, './'+option);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment