How can I get my webpage to reload with the specified id parameter positioned in the middle of the page rather than the top?

32 views Asked by At

I am trying to use a simple html script to make it so that when you reload the page with a specified id parameter, it will load with the id parameter in the middle of the page rather than how it normally loads, at the top (and highlighted in the future).

I have tried using invisible anchors, but it doesn't work for my specific site.

My initial idea was to use this script:

<script>
        if (window.history.replaceState) {
            window.history.replaceState(null, null, window.location.href);
        }
        
        window.onload = window.scrollTo( [id - half of the screen length] );
</script>

Having trouble finding the solution here

0

There are 0 answers