Last active
August 29, 2015 14:13
-
-
Save shapeshifta78/9d9cb943259a23c4b3d1 to your computer and use it in GitHub Desktop.
disable back button
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
(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