Javascript to make the page jump to a specific location

后端 未结 8 542
悲哀的现实
悲哀的现实 2020-12-13 15:09

I there a way in javascript to make the page jump to a specific location on the page, such as


         


        
8条回答
  •  执念已碎
    2020-12-13 16:02

    I realize this question is five years old, but people still find it, and it seems a shame no one has ever answered it...

    Specifically "Without Reloading Page" as asked,

    and where there is a name="HERE" or id="HERE" label somewhere in the html ("HERE" is of course an example of any label),

    then Javascript can do:

    if (navigator.userAgent.match(/Chrome|AppleWebKit/)) { 
        window.location.href = "#HERE";
        window.location.href = "#HERE";  /* these take twice */
    } else {
        window.location.hash = "HERE";
    }
    

    Works for me.

提交回复
热议问题