What's the html javascript code for after scrolling a webpage to the top then automatically reload a page (not the other way around). Thank you!
CodePudding user response:
document.onscroll = () => {
if(scrollY === 0){
location.reload()
}}
CodePudding user response:
The easiest solution will be to use js to click a link. Say that on the top of the page you have a div with id of top:
<div id="top">top section of page</div>
Then all you need to do in js is just to click on a virtual anchor element:
let a = document.createElement("a")
a.href = "#top"
a.click()
Then just call window.location.reload() to reload the page
I haven't tested this but the main idea works
CodePudding user response:
function topScrollAndRefresh() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
setTimeout(() => {
window.location.reload()
})
}
