Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

urlencode() from PHP in JavaScript?

I'm looking for similar function as urlencode() from PHP just in JavaScript. jQuery library is allowed.

Basically, I need to encode the string and then redirect the user to another page just with JavaScript.

like image 813
daGrevis Avatar asked Aug 10 '11 15:08

daGrevis


1 Answers

There is no function quite matching urlencode(), but there is one quite equivalent to rawurlencode(): encodeURIComponent().

Usage: var encoded = encodeURIComponent(str);

You can find a reference here:

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURIComponent

like image 196
Chronial Avatar answered Sep 23 '22 06:09

Chronial