Vanilla JavaScript: Scroll to Top of Page
Have you tried waiting for page load before scrollTo? Try using window.onload
window.onload = function(){
window.scrollTo(0,0);
}
Going to top of the page with a scroll effect is a bit more easier in javascript now with:
https://developer.mozilla.org/en-US/docs/Web/API/Window/scroll
window.scroll({
top: 0,
left: 0,
behavior: 'smooth'
});
CAUTION
I just checked the mozilla doc right now while updating my answer and I believe it has been updated. Right now the method is window.scroll(x-coord, y-coord) and does not mention or show examples that use the object parameter where you can set the behavior to smooth. I just tried the code and it still works in chrome and firefox and the object parameter is still in the spec.
Or in Vanilla you can use window.onload event with scrollTo(x,y) function
window.onload = function(){
window.scrollTo(0,0);
}