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

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

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 Denunciar

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 Denunciar

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