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

253
Visualizações
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 Respostas
Responde à pergunta

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 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