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

254
Vistas
JavaScript event to detect browser-side scrolling reposition on hash URLs in Firefox and IE Edge on Windows

While trying to tweak some scrolling script to perform "jump to" links on some pages, I noticed that if you have a page with contains a hash tag in the URL, the behavior is different depending on the browsers when you press enter on the address bar, after the page is loaded.

For example, if you load a page with an has in the URL and then scroll away from the target element, I noticed that on Firefox and IE, if you put your cursor on the address bar and press enter, the page will move back to the HTML element having the same id attribute as the hashtag but the page will not be reloaded.

I also noticed that neither popstate nor hashchange events are triggered in such scenario. The scroll event will most likely be triggered but how can we know this is not the user scrolling but the browser reseting back its position?

Is there any was to detect this type of event in the browsers? Given this is outside the viewport I'm a bit curious. But I have a scenario where I would like to reposition the menu depending is the page is scrolling up or down.

To try to explain what I'm looking for:

  1. Page with hashtag #test and element <div id="test">
  2. Press F5, the page posisition itself right where the <div> is
  3. Scroll up or down
  4. Go on the address bar and press enter
  5. ---- Looking for an event to detect the previous action ---
  6. the page posisition itself right where the <div> is

Example in JSBin (open in Firefox):

http://jsbin.com/rifikereze/1/edit?html,js,output

Output:

http://output.jsbin.com/rifikereze/1#test2

  1. Open your console in Firefox
  2. Make sure in the Firefox setting you enable "persistent logs" to keep logs after page reloads
  3. Press F5 (you should see a console message "reloaded")
  4. Now try to move the page, put your cursor in the address bar and press enter
  5. You will see the page does not reload

How can we detect these events (other than scroll events)?

Make sure to use Firefox on Windows if trying to reproduce. It looks like other OSes have other behaviors.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Given the lack of answer, my presumed answer is No.

There is no way to detect re-positioning of browsers using fragment identifiers (aka hash) in URLs and the address bar.

On top of this, browsers seems to have inconsistent behaviors:

  1. Firefox on Linux behave differently than on Windows (it reloads the page).
  2. Chrome seems to be ignoring re-positioning unless the page's position is set back to the top position before unloading.
  3. There seems to be no standard across browsers on whether the normal behavior is to reload or re-position.

The only safe way to detect fragment identifiers repositioning is when loading the page.

over 4 years ago · Santiago Trujillo 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