URI片段在计算机超文本中是指从属于主资源的子资源的标识字符串。主资源由统一资源标识符(URI)标识,片段标识符指向从属资源。
由井号#引入的片段标识符是文档的URL的可选最后部分。通常用于标识该文档的一部分。在RFC 3986中指定了其通用语法。[1]URI中的井号#分隔符不是片段标识符的一部分。
#
在URI中,井号#在URL末尾附近引入可选片段。RFC 3986定义的URI通用语法还允许使用问号?引入可选的查询部分。在带有查询和片段的URI中,片段位于查询之后。查询部分取决于URI方案并由服务器评估,例如,http:支持与ftp:不同的查询。片段取决于文档MIME类型并由客户端(Web 浏览器)评估。客户端在获取文档时不应将URI片段发送到服务器,并且如果没有本地应用程序的帮助,片段不会参与HTTP重定向。
?
http:
ftp:
以井号#结尾的URI是通用语法允许的,并且这是一种空片段。在MIME文档类型(例如text/html或任何XML类型)中,不允许使用空标识符来匹配此语法上合法的构造。 Web浏览器通常会在文档顶部显示一个空片段。
text/html
片段标识符的功能与URI的其余部分不同:它的处理完全是客户端进行的,没有Web服务器的参与,尽管服务器通常帮助确定MIME类型,并且MIME类型决定片段的处理。当代理(例如Web浏览器)从Web服务器请求Web资源时,代理将URI发送到服务器,但不发送片段。相反,代理等待服务器发送资源,然后代理根据文档类型和片段值处理资源。[2]
在HTML网页中,代理将查找由HTML标记标识的锚点,该标记包含等于片段标识符的id=或name=属性。
id=
name=
http://www.example.org/foo.html#bar
id="bar"
:target
display: block
display: none
name
id
xml:id
Name
xml:lang
http://www.example.org/foo.xml#xpointer(//Rube)
http://www.w3.org/2004/02/skos/core#broader
http://www.w3.org/2004/02/skos/core
text/plain
char
line
http://example.com/document.txt#line=10,20
text/csv
row
col
cell
http://example.com/data.csv#row=4
http://example.com/data.csv#col=2
http://example.com/data.csv#row=5-7
http://example.com/data.csv#row=5-*
http://example.com/data.csv#cell=4,1-6,2
t
xywh
src
http://example.com/foo.mp4#t=10,20
http://example.com/bar.webm#t=40,80&xywh=160,120,320,240
#01h25m30s
#t=3m25s
location.hash
#/foo
{ "foo": ["bar", "baz"], ... }
application/pdf
.pdf#page=35
#nameddest=
#search="word1 word2"
#zoom=
http://example.org/doc.pdf#view=fitb&nameddest=Chapter3
viewBox()
preserveAspectRatio()
transform()
对于与纯文本文档(无法存储锚元数据)一起使用的片段标识符,或者引用 HTML 文档中作者未使用锚标记的位置,已经提出了一些W3C提案:
#:~:text=foo
foo
https://pypi.python.org ... zodbbrowser-0.3.1.tar.gz#md5=38dc89f294b24691d3f0d893ed3c119c
!
http://example.com/page?query#!state
#!
?_escaped_fragment_=
history.pushState()
#!s!search terms
#!s10!
#!s-3!
http://example.com/index.html#!s3!search terms
match
http://example.com/document.txt#match=[rR][fF][cC]
words
http://example.com/index.html#:words:some-context-for-a-(search-term)
#FWS+C
#LFWS+C
http://example.com/index.html#115Fragm8+-52f89c4c
Pypi has the habit to append an md5 fragment to its egg urls, we'll use it to check the already present distribution files in the cache