Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

85
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda