Attaching hashtag to URL with javascript

后端 未结 5 1672
暗喜
暗喜 2020-12-07 20:47

I want to build an ajax site without sacrificing SEO. My question is: If I have link on my page like this:

   

        
5条回答
  •  孤城傲影
    2020-12-07 21:32

    You can change the location.hash property, it will change the current anchor identifier without navigating away form the page, for example you could:

    Cats
    Dogs
    

    Then:

    $('.ajaxLink').click(function (e) {
      location.hash = this.id; // get the clicked link id
      e.preventDefault(); // cancel navigation
    
      // get content with Ajax...
    });​
    

提交回复
热议问题