I have a problem in vanilla JS that has been asked in slightly differing forms on this site, but there doesn't seem to be an answer for vanilla javascript? I would like the page to appear at the top on reload / refresh using vanilla JS (without any scrolling back up to the top with scrollTop()).
I've checked these questions and the related answers:
Prevent automatic browser scroll on refresh
Force page scroll position to top at page refresh in HTML
Prevent automatic browser scroll on refresh
The problem is there are two vanilla JS answers scattered in these questions, one of which doesn't work in IE/Edge, the other one doesn't work in Safari
Doesn't work in Safari:
window.onbeforeunload = function () {
window.scrollTo(0,0);
};
Doesn't working in IE / Edge
history.scrollRestoration = "manual";
Surely there must a way of getting a page to appear at the top on refresh / reload?
Also I can't have it scroll up to the top on reload / refresh so any scrollTop() related answers aren't applicable.
Many thanks in advance