How AJAX is done in github source browse?

后端 未结 2 455
攒了一身酷
攒了一身酷 2020-11-28 12:39

Github has a really nice source browser. Navigating between different paths in the repo generates ajax calls to load the content (as you can clearly see in the firebug log).

2条回答
  •  被撕碎了的回忆
    2020-11-28 12:54

    You have to use HTML5's pushState() method to change browser history.

    window.history.pushState(data, "Title", "/new-url");
    

    Doc says:

    pushState() takes three parameters: a state object, a title (which is currently ignored), and (optionally) a URL.

    The last argument is the new URL. For security reasons you can only change the path of the URL, not the domain itself. The second argument is a description of the new state. And the first argument is some data that you might want to store along with the state.

提交回复
热议问题