我偶然发现了一个在其URL中使用多个片段标识符的网站,例如 www.ejeby.se/#newprodukt#produkt#1075#1 (不,这不是我的网站,但我正在链接到它,这给我带来了问题).
I stumbled across a site that uses multiple fragment identifiers in their URLs, like www.ejeby.se/#newprodukt#produkt#1075#1 (no, it is not my site, but I am linking to it, which brings problems for me).
但这真的正确吗?它似乎确实会给Safari和Internet Explorer造成问题(传闻,我本人没有尝试过IE).
But is this really correct? It does seem to cause problems for Safari and possibly also Internet Explorer (hearsay, I have not tried IE myself).
片段标识符不是应该唯一地标识文档中的一个位置吗? 这是Safari中的错误,还是www.ejeby.se以错误的方式使用片段标识符?
Isn't the fragment identifier supposed to uniquely identify one location in the document? Is this a bug in Safari or is it www.ejeby.se that uses fragment idenifiers in a wrong way?
:似乎Safari的问题是它会转义URL中除第一个外的所有#号.其他浏览器不执行此操作.行为正确与否?
Seems that the problem for Safari is that it escapes all # but the first in the URL. The other browsers do not do this. Correct behaviour or not?
推荐答案从规范的角度来看,片段可以包含以下字符(我已经扩展了作品):
From the specification point of view, a fragment can contain the following characters (I’ve already expanded the productions):
fragment = *( ALPHA / DIGIT / "-" / "." / "_" / "~" / "%" HEXDIG HEXDIG / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" / ":" / "@" / "/" / "?" )因此,不可以,该片段不能包含普通的#;它必须用%23编码.
So, no, the fragment must not contain a plain #; it must be encoded with %23.
但是某些浏览器可能会以不同的方式显示它,就像将代表有效UTF-8字符的百分比编码八位字节序列替换为它们所代表的字符一样.
But it is possible that some browsers display it differently just as sequences of percent-encoded octets, that represent valid UTF-8 characters are replaced by the characters they represent.
更多推荐
URL中的多个片段标识符正确吗?
发布评论