GitHub 如何在不重新加载页面的情况下更改 URL? [英] How does GitHub change the URL without reloading a page?

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

问题描述

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

我如何使用 jQuery 做类似的事情?

这是否适用于大多数浏览器(我使用的是 Chrome)?

解决方案

他们使用 history API,或具体来说,history.pushState().

你可以使用这个,jQuery不是必须的,但是有插件比如history.js.>

这适用于大多数浏览器,即 Chrome、Safari 和 Firefox.IE10 及以上支持这一点.在较旧的 IE 中,您可以重新使用散列 (window.location.hash).

GitHub 也就此发表了博客.

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.

How do I do something similar using jQuery?

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

解决方案

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

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

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 also blogged about this.

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

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