0

i have a problem in a one page scrolling template that used a plagin (smoothscroll.js) i try to remove hash from url after user click on link but unfortunatly i cant do it.for example

  • About Us
  • url take the hush and target(section2) like this http://localhost/template/#section2 how can i remove #section2 form the url

    here is the code

    var linkHandler = function(ev) {
    ev.preventDefault();
    
    if (location.hash !== this.hash) window.history.pushState(null, null, this.hash);
    // using the history api to solve issue #1 - back doesn't work
    // most browser don't update :target when the history api is used:
    // THIS IS A BUG FROM THE BROWSERS.
    // change the scrolling duration in this call
    smoothScroll(document.getElementById(this.hash.substring(1)), 1000, function(el) {
        location.replace('#' + el.id);
        // this will cause the :target to be activated.
    });
    

    }

    Ali Madadi
    • 39
    • 10

    1 Answers1

    0

    remove section2 from URL:

    location.hash = '';
    

    edit

    not sure why that's not working, but here's another, less efficient way:

    location.href = location.href.split('#')[0];
    
    Todd
    • 5,314
    • 3
    • 28
    • 45