Multiple parameters in URL fragment

rink.attendant.6 picture rink.attendant.6 · Apr 19, 2014 · Viewed 13.2k times · Source

Is there a standard format that allows for multiple parameters to be specified in the URI fragment? (the part after the hash #, not the query string.)

The most related information would be this question: Multiple fragment identifiers correct in URL?. The allowed characters for fragments can be found in that question as well.

Would it be acceptable to use, for instance, a semicolon to delimit multiple parameters like this:

http://example.net/page.html?q=1#param1=foo;param2=bar

Are there any unintentional behaviours that I should be aware of with this method? What if there is no such ID in the document with the value param1?

For the purposes of this question, only URIs of HTML resources are considered.

Answer

lagivan picture lagivan · May 20, 2014

I think you should read this: http://en.wikipedia.org/wiki/Fragment_identifier#Examples

So the de-facto standard format for multiple parameters should be #param1=value1&param2=value2 You can see this way is used by Media Fragments URI 1.0 and by PDF documents. There seems to be no standard for HTML resources though as you can parse the fragment in JavaScript in any way you like. But I'd use the same format as it looks more natural being similar to the query string format. If the browser cannot find any element with id/name equal to your hash fragment, it will navigate to the beginning of the document by default.

Also browsers will consider the complete hash fragment as a possible id/name. So they will look for id/name equal to param1=value1&param2=value2 but not just param1.