Differences between encodeURI, encodeURIComponent, and escape:
|
The following table illustrates the differences between URL-encoding results
obtained using encodeURI, encodeURIComponent, and escape
for lower ASCII characters, i.e. character codes up to 127
(see also Upper ASCII and
Unicode characters).
The encodeURI and encodeURIComponent functions are similar to
escape, except that escape
encodes (e.g. apostrophe, tilde, parentheses).
Additionally, encodeURIComponent encodes some characters (+ / @) that escape leaves intact.
chr escape(chr) encodeURI(chr) encodeURIComponent(chr)
_ _ _ _
- - - -
. . . .
* * * *
+ + + %2B
/ / / %2F
@ @ @ %40
~ %7E ~ ~
! %21 ! !
' %27 ' '
( %28 ( (
) %29 ) )
# %23 # %23
$ %24 $ %24
& %26 & %26
, %2C , %2C
: %3A : %3A
; %3B ; %3B
= %3D = %3D
? %3F ? %3F
all other lower-ASCII characters produce identical results:
space %20 %20 %20
" %22 %22 %22
% %25 %25 %25
< %3C %3C %3C
> %3E %3E %3E
[ %5B %5B %5B
\ %5C %5C %5C
] %5D %5D %5D
^ %5E %5E %5E
{ %7B %7B %7B
| %7C %7C %7C
} %7D %7D %7D
... ... ... ...
Copyright © 1999-2012, JavaScripter.net.