Multiple fragment identifiers correct in URL?
Asked Answered
R

1

9

I stumbled across a site that uses multiple fragment identifiers in their URLs, like http://www.ejeby.se/#newprodukt#produkt#1075#1 (no, it is not my site, but I am linking to it, which brings problems for me).

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).

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?

Edit: 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?

Ramsay answered 17/1, 2011 at 14:29 Comment(0)
A
12

From the specification point of view, a fragment can contain the following characters (I’ve already expanded the productions):

fragment    = *( ALPHA / DIGIT / "-" / "." / "_" / "~" / "%" HEXDIG HEXDIG / "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" / ":" / "@" / "/" / "?" )

So, no, the fragment must not contain a plain #; it must be encoded with %23.

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.

Almonte answered 17/1, 2011 at 17:23 Comment(5)
I don't think it just is displayed differently, since ejeby.se/#newprodukt#produkt#1075#1 in Chrome leads to the correct page, but ejeby.se/#newprodukt%23produkt%231075%231 in Safari leads to broken search result (the second to last # are escaped with %23).Ramsay
@Johan: What Safari version do you use? Because it works for me (Safari 5 on Mac) and former with # gets automatically turned into the latter with %23.Almonte
That is strange. I use Safari 5.0.3 on Snow Leopard, neither one works in Safari for me (since it escapes things, you get to a page with no search results). The first one works in Chrome/Firefox/Opera.Ramsay
I notice now the link is "javascript:;" and the url is set with javascript, like so: window.location.hash="newprodukt#"+name+"#"+id+"#"+page+" and weirdly enough, it does work when setting the (still escaped) URL with javascript, but not when it it is a regular href attribute on an <a> element. They have managed to implement links that break in Safari when linking from another site? :(Ramsay
Had forgot to mark this as accepted. It does answer the original question (with a "no, it is not correct"). Which browser does what with magic escaping etc is perhaps another question.Ramsay

© 2022 - 2024 — McMap. All rights reserved.