Question:
Some operating systems (ie: Windows and BSD) like to break lines with Carriage Return
(CR) followed by Line Feed
(LF), or \r\n
.
On the other hand, GNU/Linux, OS X and other Unix-like ones tend to break only with LF ( \n
).
Is there any way, in Javascript, to get the newline character from the client system? Any HTML 5 API or anything that allows me to achieve this without resorting to reading the user agent header of a request in order to verify the operating system?
Answer:
You can do something very close to what you want without using Javascript. The HTTP User-Agent header includes information about your client's browser and operating system, and your server can look at this when it receives the form from the client. It's not 100% accurate, as the User-Agent header value is user-configurable, but at the same time I don't believe there is any 100% sure way to know the client's OS.
Of course, another possibility is to add an extra field to your form and ask the customer what kind of line break he prefers 😛