How can I replace a window's URL hash with another response?

后端 未结 2 1425
长情又很酷
长情又很酷 2021-02-02 04:56

I am trying to change a hashed URL (document.location.hash) with the replace method, but it doesn\'t work.

$(function(){
 var anchor = document.location.hash;
 /         


        
2条回答
  •  滥情空心
    2021-02-02 05:50

    You may prefer the answer of this question.

    The difference being that with history.replaceState() you don't scroll to the anchor, only replace it in the navigation bar. It's supported by all major browsers, source.

    history.replaceState(undefined, undefined, "#hash_value")
    

提交回复
热议问题