May 14, 2007 – 2:14am javascript urlencode

In doing a google search for javascript urlencode, I realized I was using that terminology just because I was familiar with the PHP function of the same name. Javascript’s method is actually called encodeURI() which will encode all characters except:

, / ? : @ & = + $ #

But what I really wanted to do was get javascript to convert a string that would be okay to put into a query string of a URL. For this, use encodeURIComponent(). This will convert all characters except alphabetic, decimal digits, and:

- _ . ! ~ * ' ( )

That’s more like it. You can view the complete reference at mozilla or w3schools.

Posted in  Web Development   |     |  delicious  Digg

2 Responses to “javascript urlencode”

  1. This information was indeed useful. Thanks.

    By Alex on Mar 25, 2008

  2. Thank god someone remembered what that method was called :D been looking for ages =)

    By Floydan on May 6, 2008

Post a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word