如何在不刷新的情况下重写 URL,例如 GitHub.com [英] How to rewrite URL without refresh, like GitHub.com

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

问题描述

我在浏览 GitHub.com 时注意到,在查看存储库的源代码时,当您单击一个文件时,源代码滑入并且 URL 更改,但页面似乎没有刷新.有谁知道这是怎么做的?我已经看到使用 # 符号完成此操作,尤其是在创建 Flash 站点时,但我从未见过像 GitHub 所做的那样,没有 # 符号.

I was browsing GitHub.com and I noticed when looking at the source for a repository, and you click on a file, the source code slides in and the URL changes, but it doesn't appear as if the page has refreshed. Does anyone know how this is done? I've seen this done with the # sign, especially when creating Flash sites, but I've never seen this done quite like the way GitHub is doing it, without the #.

这是一个例子:https://github.com/jquery/jquery

单击其中一个文本文件,例如 .gitattributes,然后单击面包屑中的 jQuery 以了解我的意思.

Click on one of the text files like .gitattributes then click on jQuery in the breadcrumb to see what I mean.

推荐答案

Chrome/Webkit 浏览器客户端使用 XMLHttpRequest 获取服务端资源,无需刷新页面,动态加载内容,动画可在附加内容期间被吸引.

XMLHttpRequest is used on the client-side in Chrome/Webkit browsers to fetch server-side resources without page refreshing, and content is dynamically loaded in, and animations can be hooked in during that content being appended.

我不确定为什么 ajax 只针对 Chrome,因为当以相同的方式应用 ajax 时,哈希标记通常会发生变化(如 twitter).

I'm not sure exactly why only Chrome is targeted by the ajax, as usually the hash mark changes when ajax is applied in the same manner ( like twitter ).

对于动态更改的 url,我相信所做的只是更新 location.href.仔细想想,这可能是一些只有 chrome 支持的新 HTML5 功能.

For the url changing dynamically, I believe all that's done is location.href is updated. On second thought, it could be some new HTML5 feature that only chrome supports.

这篇关于如何在不刷新的情况下重写 URL,例如 GitHub.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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