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

189
Vistas
Save scroll position while doing php get request in same page

I have list of company workers. When I click to a worker, in corner of page showing workers image from mysql database. and mysql SELECT parameters I get from url:

Example:

<a href="<?php echo '?imgid=' . $imgID ?>">John SMITH</a>

How can I save my current scroll position when I'm clicking to .

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can do

var scroll_position = window.scrollY;

and to scroll there:

window.scrollTo(0, scroll_position);

You can test these out with this code in a new HTML file:

<div style="height: 400px;"></div>
<input type="button" value="Submit" id="submit" />
<div style="height: 2000px;"></div>
<script>
document.querySelector("#submit").onclick = function () {
    var scroll_position = window.scrollY;
    alert(scroll_position);
    window.scrollTo(0, 100);
}
</script>
about 4 years ago · Juan Pablo Isaza Denunciar

0

<body onload="restoreScrollPos()">  

  <a onclick="setScroll()" href="<?php echo '?imgid=' . $imgID ?>">John SMITH</a> 

</body>

<script> 
function setScroll() {
    let scroll = window.scrollY;
    let scrollString = scroll.toString();
    localStorage.setItem("scrollPosition", scrollString);
}


function restoreScrollPos() {
    let posYString = localStorage.getItem("scrollPosition");
    let posY = parseInt(posYString);
    window.scroll(0, posY);
    return true;
}
</script>
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