如何GitHub上更改URL,而不重新加载页面? [英] How does GitHub change the URL without reloading a page?

查看:531
本文介绍了如何GitHub上更改URL,而不重新加载页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

转到任何GitHub的页面,点击任何一个目录/文件并观察URL的变化,但只有部分页被更新。有没有整个页面重新加载。

Go to any GitHub page and click on any of the directories/files and observe how the URL changes but only part of the page is updated. There's no whole page reloading.

我怎样做使用jQuery类似的东西?

How do I do something similar using jQuery?

请问在大多数浏览器这项工作(我使用的是Chrome浏览器)?

Does this work on most browsers (I'm using Chrome)?

推荐答案

他们使用历史API ​​或具体而言,<一个href="https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#The_pushState%28%29.C2.A0method"><$c$c>history.pushState().

They use the history API, or specifically, history.pushState().

您可以使用此,jQuery是不是必需的,但也有插件,如 history.js

You can use this, jQuery is not required, but there are plugins such as history.js.

这适用于大多数浏览器,即Chrome浏览器,Safari和Firefox。 IE10及以上支持这一点。在老的IE,你可以后退到使用散列( window.location.hash )。

This works on most browsers, namely Chrome, Safari and Firefox. IE10 and above supports this. In older IEs, you can fall back onto using the hash (window.location.hash).

GitHub的博客上也对此

这篇关于如何GitHub上更改URL,而不重新加载页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆