[removed].hash = “ ”; prevent scrolling to the top?

后端 未结 4 918
无人共我
无人共我 2020-12-10 01:33

in my website i set the url adress using

window.location.hash = \'project_name\';

but if i want to clean the adress url from any hashes (wh

4条回答
  •  情话喂你
    2020-12-10 02:13

    document.body.scrollTop is deprecated, also latest Chrome versions seem to be unstable here. The following should work:

      var topPos = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
      window.location.href = '#';
      document.documentElement.scrollTop = topPos;
    

提交回复
热议问题