Per the answer found here: How to escape Hash character in URL
Replace #
with %23
.
You can find a list of all the reserved characters here: Percent-encoding.
A word on JavaScript encoding
encodeURI(str)
"Assumes that the URI is a complete URI, so does not encode reserved characters that have special meaning in the URI. encodeURI
replaces all characters except the following with the appropriate UTF-8 escape sequences:" [1]
encodeURIComponent(str)
"Escapes all characters except the following: alphabetic, decimal digits, - _ . ! ~ * ' ( )" [2]
In your case, you would use encodeURIComponent()
, only on your query string, to escape any and all reserved chracters.
! %21
# %23
$ %24
& %26
' %27
( %28
) %29
* %2A
+ %2B
, %2C
/ %2F
: %3A
; %3B
= %3D
? %3F
@ %40
[ %5B
] %5D