Parsing navigator.userAgent can be a fairly reliable way to detect the OS and, therefore, use a newline.
Something like this would probably do the trick - it might take some tweaking on UA ββstrings that are tested for individual platforms.
Also, this will not work if the UA is tampered with.
function getLinebreak (){ var linebreaks = { Windows: "\r\n", Mac: "\n", Linux: "\n" } for(key in linebreaks){ if(navigator.userAgent.indexOf(key) != -1){ return linebreaks[key]; } } return "\n"; }
Note. You can probably just check to see if Windows otherwise leads \ n in most cases
Something like this will probably work in most cases:
function getLinebreak(){ if(navigator.userAgent.indexOf("Windows") != -1){ return "\r\n"; } return "\n"; }
Brian
source share