Home Javascript How to encode a URL in JavaScript?
 
 
 

How to encode a URL in JavaScript?

PDF Print E-mail

Question: How to encode a URL in JavaScript?

 

Answer: 

There are two JavaScript function that you can use to accomplish this

  1.  encodeURIComponent()
    • Encodes a URI component
    • Encodes special characters
    • The following characters: , / ? : @ & = + $ # are encoded
    var url="http://test.com/index.php?url"+encodeURIComponent(url);
  2. encodeURI()
    • Encode a URI
    • Encodes special characters but not (except) , / ? : @ & = + $ #
    var url="http://test.com/index.php?url"+encodeURI(url);
+/-
+/- Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Security Please input the anti-spam code that you can read in the image.
 
 
Banner