location.hash and back history

前端 未结 2 559
臣服心动
臣服心动 2020-12-15 07:42

Is there a function that can be called to prevent the browser from recording a back history entry when changing the hash value?

I am writing a simpl

2条回答
  •  执笔经年
    2020-12-15 08:19

    window.location.replace will let you set the url without adding it to the browser history.

    var baseUrl = window.location.href.split('#')[0];
    window.location.replace( baseUrl + '#' + imageID );
    

    documentation

提交回复
热议问题