Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

82
Visualizações
Is there a way to scroll to URI fragments without adding them to history?

I have some URI fragments in an app I'm building that will jump to elements within the page as expected, however, clicking on these fragment links also adds them to the history so if I navigate to another page and click back, it will navigate to the last page AND the fragment last used when I'd prefer to not have fragments modify the history so clicking back just takes me to the top of the previous page without auto-scrolling to the last fragment.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You may want to use the Element.scrollIntoView to scroll to an element in the document without affecting the current URL or history.

So, instead of a link like

<a href="#next-section">Scroll to next section</a>

You would have

<a href="#" onclick="document.querySelector('#next-section').scrollIntoView(); event.preventDefault();">Scroll to next section</a>

Or the equivalent code in a separate JavaScript file: basically, find the element you want to scroll to using the DOM API (with document.querySelector, document.getElementById, etc.), and then call scrollIntoView on the element.

If the element that receives the click event is a link (<a>), you will also need to call event.preventDefault() to override the default behavior of navigating to the href target (note that you may still need a dummy href attribute for the expected styling).

<a href="#" onclick="document.querySelector('#next-section').scrollIntoView(); event.preventDefault();">Scroll to next section</a>

<div style="height: 8.5em;"></div>
<h2 id="next-section">Next section</h2>
<div style="height: 7em;"></div>
<h2 id="another-section">Another section</h2>
<div style="height: 5em;"></div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda