我正在使用片段标识符为我的网络应用similar to this guy中的AJAX事件创建永久链接。类似的东西:
http://www.myapp.com/calendar#filter:year/2010/month/5
我已经做了很多搜索,但找不到片段识别符的有效字符列表。 W3C spec没有提供任何内容。
我是否需要将字符编码与一般的URL相同?
在任何地方似乎都没有任何好的信息。
答案 0 :(得分:90)
请参阅RFC 3986。
fragment = *( pchar / "/" / "?" )
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
因此,您可以使用!
,$
,&
,'
,(
,)
,*
,{ {1}},+
,,
,;
,匹配=
的内容,匹配%[0-9a-fA-F]{2}
,[a-zA-Z0-9]
,-
的内容,.
,_
,~
,:
,@
和/
答案 1 :(得分:29)
http://tools.ietf.org/html/rfc3986#section-3.5:
fragment = *( pchar / "/" / "?" )
和
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
/ "*" / "+" / "," / ";" / "="
pct-encoded = "%" HEXDIG HEXDIG
因此,合并后,片段不能包含#
,原始%
,^
,[
,]
,根据RFC,{
,}
,\
,"
,<
和>
。
答案 2 :(得分:0)
另一个RFC说的是:RFC-1738
URL schemeparts for ip based protocols:
HTTP
httpurl = "http://" hostport [ "/" hpath [ "?" search ]]
hpath = hsegment *[ "/" hsegment ]
hsegment = *[ uchar | ";" | ":" | "@" | "&" | "=" ]
search = *[ uchar | ";" | ":" | "@" | "&" | "=" ]