The JavaScript Programming Language

Escaping characters

Many times in URLs it is needed to escape string characters:

There are three options:

  • escape() will not encode: @*/+

  • encodeURI() will not encode: ~!@#$&*()=:/,;?+'

  • encodeURIComponent() will not encode: ~!*()'

If you want to pass URL into a GET parameter of other page, you should use escape or encodeURIComponent, but not encodeURI.