Last active
February 6, 2018 09:24
-
-
Save FranciscoGutierrez/ae96f3af90f8f6fd6d8e923212a334da to your computer and use it in GitHub Desktop.
a simple script to prevent user to going back in the browser.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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