Skip to content

Instantly share code, notes, and snippets.

@z2015
Created July 21, 2016 08:28
Show Gist options
  • Save z2015/a640ae25d2cb6ea3fedba54f1b56bd60 to your computer and use it in GitHub Desktop.
Save z2015/a640ae25d2cb6ea3fedba54f1b56bd60 to your computer and use it in GitHub Desktop.
Prevent automatic browser scroll on refresh
$(window).on('unload', function() {
$(window).scrollTop(0);
});
window.onunload = function(){ window.scrollTo(0,0); }
if ('scrollRestoration' in history) {
history.scrollRestoration = 'manual';
}
//http://stackoverflow.com/questions/18617367/disable-browers-auto-scroll-after-a-page-refresh
//http://stackoverflow.com/questions/7035331/prevent-automatic-browser-scroll-on-refresh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment