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

后端 未结 2 1398
长情又很酷
长情又很酷 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:39

    Either use location or window.location instead of document.location as the latter is a non-standard.

    window.location.hash = '#food';
    

    This will replace the URL's hash with the value you set for it.

    Reference

提交回复
热议问题