title: Can I change CSS scroll-behavior from JavaScript?
body: <p>I am trying to have my page snap to the top when the page is reloaded. To do this I am using JavaScript like so:</p>
  
  <pre><code>window.onbeforeunload = function() {
     window.scrollTo(0,0);
  }
  </code></pre>
  
  <p>This was working great for me until I turned on smooth scrolling in my CSS:</p>
  
  <pre><code>scroll-behavior: smooth;
  </code></pre>
  
  <p>And now it won't work at all.</p>
  
  <p>What I'd like to be able to do is temporarily turn off the CSS smooth scrolling behavior from JS something like this:</p>
  
  <pre><code>window.onbeforeunload = function() {
     document.getElementsByTagName("HTML")[0].style.scrollBehavior = "auto";
     window.scrollTo(0,0);
  }
  </code></pre>
  
  <p>However it looks like <strong>style.scrollBehavior</strong> isn't valid and I can't find anything that is. Is it possible to change this from JavaScript?</p>
  
  <p>If not is there a way to turn smooth scrolling on and off from within JavaScript that is fairly simple?</p>
  
  <p><em>I just would like to keep things pretty straight forward if possible.</em></p>