7
Some operating systems (i.e.: Windows and BSD) like to break lines with Carriage Return
(CR) followed by Line Feed
(LF), or \r\n
.
Already GNU/Linux, OS X and other Unix-like usually break only with LF (\n
).
Is there any way, in Javascript, to get the line break character of the client system? Some HTML 5 API or anything that allows me to get this without appealing to the header reading user agent of a request in order to verify the operating system?
I did not find an answer, but I did not understand what I meant by "appeal to the reading of the header user agent of a request". To my knowledge, this information is available via
window.navigator
(and from thereoscpu
,platform
oruserAgent
- what is more reliable/easy to interpret), and can be used to infer the type of line break. Incidentally, just out of curiosity, what do you intend to do in possession of this information?– mgibsonbr
I’ll check the type of user line break to assemble a text and make a request to the server. From the request a file will be generated and I will redirect the user to that file. I wish the file had user system breaks.
– Oralista de Sistemas
Why the fact that the line break is with CR or LF is important in this case?
– gabrielhof
@gabrielhof wanted the breaks to be straight in the text editors (friends of mine THE X'istas complain when they have r, I Windows'ista complain when they do not have), but I confess that there is also a mixture of academic curiosity with pedance on my part.
– Oralista de Sistemas
Will this text be generated and displayed in the browser? As for the server, what do you do with the text in it?
– gabrielhof
As a curiosity, it is interesting. For practical use, I cannot imagine. Ex: A user with Linux records the output on a USB stick, delivers the USB stick to a friend who uses Windows, who will need the text. We have just lost all effort to rely on the OS of the request to decide the output format (remembering that if it is to use with http only, the line break is part of the standard specification, not OS).
– Bacco
@gabrielhof use as input to make a request that mounts a file, and then force the download of the file.
– Oralista de Sistemas
Well, in that case, I think you’d better just standardize
\n
due to the case @Bacco cited.– gabrielhof
I’m coming to that conclusion too. But I was still wondering if it’s possible to get the line separator just out of curiosity right now.
– Oralista de Sistemas