javascript – LINK Anchor to Section Not Working in FireFox

Question:

$(window).load(function() {
  $('a.scroll').each(function() {
    var id = $(this).attr('href');
    if (id.match('^#')) {

      var target = $(id).offset().top - 65;
      var title = $(this).attr('title');

      $(this).on('click tap', function() {
        $('body').animate({
          scrollTop: target
        }, 1000);
        history.pushState({
          foo: title
        }, title, id);
        return false;
      });
    }
  });
});

same page

<a href="pecas-servicos#qualidade" class="scroll" title="{!! trans('master.menu.qualidade')">Qualidade</a>

Another Page

<a href="pecas-servicos/contato#qualidade" class="scroll" title="{!! trans('master.menu.qualidade')">Qualidade</a>

When I'm on the HOME page and I click on the LINK it works scrolling to the section I clicked on.

But if I'm on another page the same doesn't happen. It even goes to HOME, however, it goes down to the bottom of the page.

Answer:

It does not recognize the post via strange Script not working only in Firefox. Two things I would try.

  1. Placing the Full URL follows a test I put on my site ( http://papoinformal.com.br/teste/anchor.html );
  2. Force the URL by taking the parameter and find the correct part of the page like this ( https://stackoverflow.com/questions/19491336/get-url-parameter-jquery );

Tell me later if any of them worked.

Scroll to Top