2

I'm using hash-based navigation in my rich web app. I also found I needed to create permalinks that would point to single instances of resources, but since I cannot cause the page o refresh, and the main page is loaded from a single path '/', I cannot use real URLs. Instead I thought about using hashes. Let me give you an example because I know the explanation above sucks.

So, instead of having http://example.com/path/to/resource/1, I would have http://example.com/#path/to/resource/1

This seems to work ok, and browser believes '#path/to/resource/1' is a hash (slashes permitted, I think) but I was wondering about what characters are allowed in URL hash. Is there a specification or a RFC that I could read to find out what the standard behavior of browsers is when it comes to hashes?

EDIT: Ok, so silly me. Didn't actually check if slashes worked in all browsers. Chrome obviously doesn't like them. Only works in FF.

  • 1
    `Didn't actually check if slashes worked in all browsers. Chrome obviously doesn't like them. Only works in FF.` - Hmm, I've had no problem in Chrome or any browser for that matter. – Wesley Murch May 03 '11 at 09:20
  • @Wesley: Dunno, I started using them becuse FF 3.6 agreed it was a good idea. And then I tested in Chrome which behaved differently. –  May 04 '11 at 10:18

3 Answers3

5

Look at: http://www.w3.org/Addressing/rfc1630.txt or http://www.w3.org/Addressing/URL/4_2_Fragments.html

Basically you can use anything that can be encoded in an URL.

Note: There might be browser inconsistencies. If you fear them, you might use a serialization mechanism, like converting the string to hex or something (will be twice longer though), or use an id of some sort.

Nicolas Goy
  • 1,294
  • 9
  • 21
1

This document should help. Slashes are allowed, but the lexical analysis might differ between browsers.

jwueller
  • 30,582
  • 4
  • 66
  • 70
  • Yeah, Chrome definitely doesn't think slashes are part of the hash, so I reverted to dashes. Thanks for the link, though. –  May 04 '11 at 10:15
0

I think you might find that useful: RFC3986

If you use PHP to generate your page paths you could also urlencode() which generates you a valide URL.

elonmir
  • 27
  • 1
  • 7
  • I do everything in JavaScript. That's why I need hashes instead of regular URLs. –  May 04 '11 at 10:14