Although the standard defines many escape sequences (see table), how these are displayed depends very much on the way that the implementation uses the output of JavaScript:
Escape Sequence | Name | Symbol |
\" | Double Quote | " |
\' | Single Quote (Apostrophe) | ' |
\\ | Backslash | \ |
\a | Audible alert (MSIE displays the letter a) | <BEL> |
\b | Backspace (ignored silently in MSIE) | <BS> |
\f | Form Feed (ignored silently in MSIE) | <FF> |
\n | Line Feed (Newline - MSIE inserts a space) | <LF> |
\r | Carriage Return (MSIE inserts a space) | <CR> |
\t | Horizontal Tab (MSIE inserts a space) | <HT> |
\v | Vertical tab (MSIE displays the letter v) | <VT> |
\0nn | Octal escape | - |
\042 | Double Quote | " |
\047 | Single Quote (Apostrophe) | ' |
\134 | Backslash | \ |
\xnn | Hexadecimal escape | - |
\x22 | Double Quote | " |
\x27 | Single Quote (Apostrophe) | ' |
\x5C | Backslash | \ |
\unnnn | Unicode escape | - |
\u0022 | Double Quote | " |
\u0027 | Single Quote (Apostrophe) | ' |
\u005C | Backslash | \ |
\uFFFE | A special Unicode sentinel character for flagging byte-reversed text | - |
\uFFFF | A special Unicode sentinel character | - |
Encoding line feeds, form feeds, and tabs into data that ultimately gets output as part of a document.write() method suggests that the target is an HTML page. When HTML is rendered, any embedded tabs and line terminators have no effect at all on the displayed output apart from some undesirable side effects in older browsers, which used to display line terminators inside anchor tags in a very odd way.
On the other hand, JavaScript that is generating a text data stream that is going to be returned via a TCP socket may well want to encode all kinds of escaped control characters.
Generally a browser will ignore any escape sequences it cannot cope with. Some it will ignore silently such as a \b which results in no output in the MSIE browser. For others, such as \a, MSIE ignores the backslash but writes the letter 'a' into the document output. A few escape characters result in a space character being inserted into the output text.
You should, as a matter of course, clean your HTML text of any unwanted escape characters if you can.
See also: | Character set, Environment, Escape sequence (\) |
Prev | Home | Next |
Character constant | Up | Character entity |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |