How to escape the # hash sign (sometimes known as number sign or pound sign) sent in the query string of a URL?
Asked
Active
Viewed 1.7e+01k times
212
Robert Tupelo-Schneck
- 9,318
- 4
- 43
- 54
Muhammad Hewedy
- 27,782
- 43
- 120
- 210
1 Answers
355
Percent encoding. Replace the hash with %23.
Robert Tupelo-Schneck
- 9,318
- 4
- 43
- 54
-
Useful if you want to share a url which contains '#' to twitter – Raynal Gobel Apr 05 '18 at 02:13
-
4This doesn't work on Chrome 74. Furthermore, `encodeURI('#');` is returning `#` and not the percent encoded character – Cristian Traìna May 20 '19 at 12:10
-
23`#` is a valid URI character, but it starts the [hash fragment](https://en.wikipedia.org/wiki/Fragment_identifier), so you need to encode it in the query string. Compare `encodeURIComponent('#')`. What do you see in Chrome 74? – Robert Tupelo-Schneck May 21 '19 at 14:48