Search code examples
javascripturiuriencoding

URIencode and colon


colon is a character which can be encoded to '%3A' as per many sites and when I try to encode using URIencode it is not working

for example if I try to encode like URIencode(':'); then nothing happens. colon is returned. Why is this?? can someone help me out here.

Thanks in advance.


Solution

  • The encodeURI() encodes special characters, except:

    , / ? : @ & = + $ #

    You should use this instead encodeURIComponent(':');

    This function encodes special characters. In addition, it encodes the characters skipped by encodeURI()