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

后端 未结 4 922
无人共我
无人共我 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:19

    I was having the same problem and came here for an answer. Just found out there is a very easy way:

    window.location.hash = ' ';
    

    Basically you are setting it to '# ', since the space doesn't exist, it doesn't move. When you revisit the page, it also doesn't treat it any differently than just #

提交回复
热议问题