[thelist] JavaScript substring and linebreaks on IE & Firefox bug..

Andrew Clover and-evolt at doxdesk.com
Thu May 25 21:11:09 CDT 2006


Mark Mandel wrote:

> It seems that when you have linebreaks in a string (i.e. text from a
> textfield), the way that IE handles it, and the way Firefox handles it
> are completley different. One counts line breaks, and one doesn't.

This is nothing to do with substr[ing], but the way IE reads the 
contents of <textarea>.

If you step through textarea.value alert()ing charCodeAt(), you'll see 
that it gives the two-character CRLF sequence '\x0D\x0A' on every 
newline. This is regardless of whether the original HTML file used CRLF 
newlines. Opera does the same. Mozilla browsers, on the other hand, use 
just '\x0A'.

Mozilla's behaviour is correct for XML processing rules. Legacy-HTML 
parsing rules for this don't seem to be well-defined.

-- 
And Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/



More information about the thelist mailing list