Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
59
rated 0 times [  64] [ 5]  / answers: 1 / hits: 21319  / 12 Years ago, mon, november 26, 2012, 12:00:00

w3schools says the following about encodeURIComponent function:




This function encodes special characters. In addition,
it encodes the following characters: , / ? : @ & = + $ #.




Does that mean that it cannot encode a backslash ()?


More From » encoding

 Answers
58

This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ # .




This definition is vague as to what special characters are. It sounds like a comparison between encodeURI and encodeURIComponent. Both will correctly escape as %5C, so you don't have to worry about backslashes.



encodeURI will leave the listed characters as it is assumed that the entire URI is being encoded:



encodeURI('http://example.com/foo bar/baz.html');
//produces http://example.com/foo%20bar/baz.html


encodeURIComponent will escape everything as it is assumed that the string is to be used as part of a query-string:



'http://example.com?foo=' + encodeURIComponent('http://example.com/fizz/buzz.html');
//produces http://example.com?foo=http%3A%2F%2Fexample.com%2Ffizz%2Fbuzz.html

[#81793] Saturday, November 24, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andrewb

Total Points: 259
Total Questions: 124
Total Answers: 90

Location: Ivory Coast
Member since Sun, Mar 7, 2021
3 Years ago
;