Working with single page websites and maintaining state using a URL hash and jQuery

后端 未结 4 1990
孤独总比滥情好
孤独总比滥情好 2020-12-01 06:08

I\'m working on my portfolio, making it entirely jQuery based. So my problem is when you go to a page, then refresh then it will take you to the home page again. So I have t

4条回答
  •  没有蜡笔的小新
    2020-12-01 06:19

    You make the anchor point to an internal link like so:

    Graphics
    

    And then simply make jQuery respond to the click event and let the browser follow the internal link naturally. The browser should now have the internal link in it's address bar. You can use the following JavaScript to parse the URL and then load the correct part of the HTML document. You will need to write the code so that the correct content is loaded based off what the browsers internal address is.

    if(window.location.hash === "graphicsDesign" ||
    window.location.hash === "somethingElse") {
        loadContent(window.location.hash);
    }
    

提交回复
热议问题