|
October 5, 2000 Escaping Separators in mailto: URLs Tips: October 2000
Yehuda Shiran, Ph.D.
|
|
Sometimes you need to substitute characters with their ASCII values, written in a hexadecimal notation. Numbers in hexadecimal notation are written in base 16. A percent sign in the beginning of a number in JavaScript denotes an hexadecimal number. The ASCII code of the Space character, for example, is 32, or %20 in hexadecimal. To convert a two-digit hexadecimal number to decimal, you multiply the left digit by 16 and add it to the right digit (2*16+0=32). Converting characters to hexadecimal is called hex-encoding. Normally, you would want to convert all characters other than letters and numbers. The JavaScript's escape() function does it for you. Let's take, for example, the following script:
The value of
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 Learn more about encoding and decoding URLs in Column 59, IE 5.5: Formatting, URIs, and Stack Operations.
People who read this tip also read these tips: Look for similar tips by subject: |