0

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!

  • html is the language used to describe documents on the web. JavaScript is a programming language. Might be time to revisit the basics.[html](https://developer.mozilla.org/en-US/docs/Web/HTML) [javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript) – nlta Jan 23 '22 at 20:43
  • does [this](https://stackoverflow.com/a/48163408/18001301) answers your question? – Sarout Jan 27 '22 at 09:04

3 Answers3

1
document.onscroll = () => {
    if(scrollY === 0){
    location.reload()
}}
stackzebra
  • 450
  • 1
  • 6
  • 13
0

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

wyvern
  • 116
  • 1
  • 7
0
function topScrollAndRefresh() {
  document.body.scrollTop = 0;
  document.documentElement.scrollTop = 0;
  setTimeout(() => {
      window.location.reload()
  })
}
soumitra
  • 91
  • 2
  • 14