Home > Back-end >  How to jump to a specific section of a page after location.reload() in js?
How to jump to a specific section of a page after location.reload() in js?

Time:10-23

I am reloading a specfic page . But after reloading it is jumping to the top of the page which i dont want . Is there any other way where i can jump to a specific section so that it scrolls by itself to that section after reloading.

CodePudding user response:

Js has a function document.location.reload() which stores the position. You can add an additional true parameter to force reload, but without restoring the position.

document.location.reload(true)

CodePudding user response:

Use location.href with address hook instead of location.reload

Like this:

window.location.href = window.location.href '#my_hoock';
First content</br>
First content</br>
First content</br>
First content</br>

<div id="my_hoock">Div for show after reload</div>

Second content</br>
Second content</br>
Second content</br>
Second content</br>

  • Related