quote:
Originally posted by Eljay
Unfortunately, using encodeURI doesn't encode parentheses (it appears JScript 5.6 is older than the latest RFC about URIs ) so it doesn't really help.
Hence why I suggest to use
escape() instead (in this situation).
The reason why they suggest not to use
escape() has to do with how it handles other characters (eg: it encodes some characters which don't need to be encoded) and that it, therefor, can't be used on a complete link (eg: it also encodes ":" in the "http://" part, and the ampersand & and equal sign = in a query string).
But this is better than not encoding certain characters which should best be encoded (like the parenthesis).
In short, for 'simple' links, in ascii format,
without any query components or anchors, the
escape() method is a proper (and safer) method to use though as long as you don't include the "http://" part.
Ori: http://www.this.com/that.html (spaced)?data1=1&data2=1#anchor4
escape() => http
%3A//www.this.com/that.html%20%28spaced%29
%3Fdata1
%3D1
%26data2
%3D1
%23anchor4
encodeURI() => http://www.this.com/that.html%20
(spaced
)?data1=1&data2=1#anchor4
http://xkr.us/articles/javascript/encode-compare/
http://www.the-art-of-web.com/javascript/escape/