How to make so that when redirecting through header () the current position on the page remains in its place and does not flip to the top of the page?

  • one
    the current doesn’t seem like, just by hashes, something like header ("Location: / page / # something"); - DaemonHK

1 answer 1

You can encapsulate a JS that shakes to a specific place. And then already tied to some element. Well, either before the redirect, forward the scroll position. Although for different pages the height may be different and therefore the scroll may not fall.

/page?pos=1443 document.getScroll= function(){ if (window.pageYOffset!= undefined) { return [pageXOffset, pageYOffset]; } else { var sx, sy, d= document, r= d.documentElement, b= d.body; sx= r.scrollLeft || b.scrollLeft || 0; sy= r.scrollTop || b.scrollTop || 0; return [sx, sy]; } }; document.getScroll(); window.scrollTo(0, 1443); 

Scroll to the desired item can be

 /page?elm=answer-836245 document.getElementById('answer-836245').scrollIntoView(); 

PS But something tells me that you are not doing that