在URL中清除哈希



我用bootstrap制作了一个网站,其中包含两个页面:

index.html
Impressum.html

我想在index.html中使用页面跳跃,并访问Impressum Asell的这些页面跳跃。这可以正常工作,但是一旦我单击一个页面跳跃,就会从iMpressum.html跳到URL中,不会消失。

您可以使用这样的JavaScript:

function clearHash(){
  var uri = window.location.toString();
  if (uri.indexOf("#") > 0) {
      var clean_uri = uri.substring(0, uri.indexOf("#"));
      window.history.replaceState({}, document.title, clean_uri);
  }
}

然后在滚动事件上触发功能:

$(window).scroll(function(){
    clearHash();
});

(我假设您是因为Bootstrap而使用的)

最新更新