SUBSCRIBE VIA RSS


Subscribe to our feed

Symfony Experts

Symfony Experts
If you have an urgent question for a symfony-related issue, this is the place to ask.

Topics

TWITTER

Stack Overflow


The old fashioned way

RECENT TUNES

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

5 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

  3. Thanks! There are tons of website wrong about this…
    At last I found your post that is right ! ;-)

    By Michel on Aug 21, 2008

  4. Glad you found this useful!

    By Scott Meves on Aug 21, 2008

1 Trackback(s)

  1. Nov 3, 2008: UrlEncode in Javascript? Call me encodeURI « ?????

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