Clear Hash in URL

293 Views Asked by At

I made a site with Bootstrap which contains two pages:

index.html
impressum.html

I want to use page jumps inside index.html and access those page jumps from the impressum aswell. This works fine but as soon as I click on a page jump from the impressum.html it stays in the URL and won't go away.

1

There are 1 best solutions below

1
On BEST ANSWER

You could use a little of JavaScript like this:

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);
  }
}

And then trigger the Function on the scroll event:

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

(I'm assuming that you are using JQuery because of the Bootstrap)