October 5, 2000 - Escaping Separators in mailto: URLs
October 5, 2000 Escaping Separators in mailto: URLs Tips: October 2000
Yehuda Shiran, Ph.D.
|
escape()
function does it for you. Let's take, for example, the following script:
var myString = "Read Doc JavaScript's daily tips & biweekly columns!";
var myEncodedString = escape(myString);
The value of myEncodedString
will be:
Read%20Doc%20JavaScript%27s%20daily%20tips%20%26%20biweekly%20columns%21
Some applications require you to use hex-encoding. A JavaScript command syntax may call for an ampersand, for example, and thus any ampersand in your original string will cause JavaScript to misinterpret the command. This is the case with the mailto
URL. The question mark is used as a delimiter between the mail address and the rest of the URL, and the Ampersand character is used as a delimiter between name/value pairs. If a string includes these characters (?
or &
), it could not be used as a subject or a body value in a URL. Be sure to encode only the subject and message body values in a mailto
URL. Do not encode the delimiters of the URL (?
and &
). Another way to represent a space is by the +
sign. The value Doc JavaScript could appear in the URL as Doc+JavaScript.
Learn more about encoding and decoding URLs in Column 59, IE 5.5: Formatting, URIs, and Stack Operations.