URL Encoding And Decoding
When constructing
URL it is important to encode it properly. Some characters have to be
converted to hexadecimal and preceded with a % sign. JavaScript provides
two methods that can be used to encode: escape() and decode: unescape()
a string. Try the box below for an example.
Examples:
Example 1.
The following example returns "%26":
escape("&");
// returns "%26"
Example 2.
The following statement returns a string with encoded characters for
spaces, commas, and apostrophes.
escape("The_rain. In Spain, Ma'am");
// returns
"The_rain.%20In%20Spain%2C%20Ma%92am"
|