How can I escape the # hash sign (sometimes known as number sign or pound sign) sent in the query string of a URL?
1 Answer
Percent encoding. Replace the hash with %23.
-
Useful if you want to share a url which contains '#' to twitter Commented Apr 5, 2018 at 2:13
-
5This doesn't work on Chrome 74. Furthermore,
encodeURI('#');is returning#and not the percent encoded character Commented May 20, 2019 at 12:10 -
28
#is a valid URI character, but it starts the hash fragment, so you need to encode it in the query string. CompareencodeURIComponent('#'). What do you see in Chrome 74? Commented May 21, 2019 at 14:48 -
3You must also encode a
#anywhere in adata:URL, otherwise it will be treated as a fragment identifier. Commented Dec 12, 2022 at 19:20