Javascript to make the page jump to a specific location

后端 未结 8 534
悲哀的现实
悲哀的现实 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 15:59

    Try this (using JavaScript):

    location.hash = "div-Name";
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题