开发者

URL hash format, what's allowed and what's not?

开发者 https://www.devze.com 2023-03-02 17:02 出处:网络
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

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,开发者_Python百科 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.


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号