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

188
Visualizações
How to open page at a certain position?

How can I set and get the current web page scroll position?

I have a chat with position fixed and if you decide to close it, the page reloads and goes back to top, which is annoying for users..because they have to scroll back down to the point they were at.

If I could save the current scroll position (in a hidden input) before the page reloads, I could then set it back after it reloads.. right? But please, show me how to do it because I am new to this.

function closeChat() {
    var x = document.getElementById("chatArea");

    if(x.style.display == 'block'){
        x.style.display = 'none';
    }
    
    window.location.assign("explore.php");
    return false;
}

PS: I have to assign to the same page because I am sending a parameter through the url and when the chat is closed, the parameter is still there... so that's why

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

0

Yes, you can save the position of the scroll in your closeChat function and store it in your localstorage

function closeChat() {
    var x = document.getElementById("chatArea");

    if(x.style.display == 'block'){
        x.style.display = 'none';
    }
    localStorage.setItem('scrollValue', window.scrollY) // set it here
    window.location.assign("explore.php");
    return false;
}

Then on page load, you just add that value to window.scrollTo(x, y)

const scrollValue = localStorage.getItem("scrollValue")
window.scrollTo(0, scrollValue ? scrollValue : 0)
about 4 years ago · Juan Pablo Isaza Relatório

0

Maybe you should try to get the scrollTop property of the element under the chat box. Then you store it in the local storage and access it upon closing the the chatbox.

about 4 years ago · Juan Pablo Isaza Relatório

0

you can save the current scroll in local storage and restore it when the page reloads

// when leaving the page
window.localStorage.setItem('scroll', x.scrollTop);


// when entering the page
x.scrollTop = localStorage.getItem('scroll');

hope it helped :)

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