从URL中删除锚点

时间:2015-02-26 17:54:48

标签: javascript jquery html anchor

我使用该代码滚动到锚点:

$(function() {
  $('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;
      }
    }
  });
});

当您点击" Contato"时,您可以在标题菜单上查看here

但每次滚动到div时,我的网址都会更改为www.mcsoftware.com.br/sitemc/#nameofthediv

是否可以将其删除?

0 个答案:

没有答案