1

I am making a static website in which I am using href to go to particular div/section and which is working flawlessly. But I am trying to remove id of a div from address bar "http:localhost:3000/index.html/#about" when user clicks particular link.

Index.html

<a href="#about">About</a>
<a href="contacts">Contacts</a>

<section id="about></section>

<section id="contacts"></section>
fiza khan
  • 1,280
  • 13
  • 24
user3869304
  • 853
  • 2
  • 11
  • 23

2 Answers2

1

This is the simplest way to do it:

<a href="#About" id="aboutButton">About</a>

I added that ID for this event listener:

document.getElementById("aboutButton").addEventListener("click", function() {
    window.location.href = location.pathname;
)}

This will remove everything from address bar after .html

Yogesh Patel
  • 818
  • 2
  • 12
  • 26
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
0

This block of code worked for me

 $(function() {
  // Smooth Scrolling
  $('a[href*="#"]:not([href="#"])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html, body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });
});
user3869304
  • 853
  • 2
  • 11
  • 23