Skip to content

Instantly share code, notes, and snippets.

@kyungmi
Forked from z2015/preventrefresh.js
Created December 4, 2018 10:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kyungmi/a246a2e782423bba950dbfd292268416 to your computer and use it in GitHub Desktop.
Save kyungmi/a246a2e782423bba950dbfd292268416 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
@Adborowski
Copy link

Thanks a lot for this, it helped me.

@mattnadd
Copy link

Thanks for code.

@naritai
Copy link

naritai commented Dec 16, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment