Skip to content

Instantly share code, notes, and snippets.

@shapeshifta78
Last active August 29, 2015 14:13
Show Gist options
  • Save shapeshifta78/9d9cb943259a23c4b3d1 to your computer and use it in GitHub Desktop.
Save shapeshifta78/9d9cb943259a23c4b3d1 to your computer and use it in GitHub Desktop.
disable back button
(function (w) {
w.location.hash = '#no-back';
var historyApi = (typeof w.history.pushState !== 'undefined');
if (w.location.hash == '#no-back') {
if (historyApi) {
w.history.pushState(null, '', '#stay');
} else {
w.location.hash = '#stay';
}
function hashChanged() {
if (w.location.hash == '#no-back') {
if (historyApi) {
w.history.pushState(null, '', '#stay');
} else {
w.location.hash = '#stay';
}
}
}
if (w.addEventListener) {
w.addEventListener('hashchange', hashChanged, false);
} else if (w.attachEvent) {
w.attachEvent('onhashchange', hashChanged);
}
}
})(window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment