A few years ago, I wrote the following function for one of my Firefox add-ons, which helps me get the character of a new line of a new line:
GetNewLine: function() { var platform = navigator.platform.toLowerCase(); if(platform.indexOf('win') != -1) // Windows return "\r\n"; else if(platform.indexOf('mac') != -1) // Mac return "\r"; else // *nix return "\n"; }
This seems to work fine, but after reading through the article on the new Wikipedia article, I noted that the latest Apple operating systems (OS X and above) now use the UNIX-style end of line \n . Thus, my little function may return the wrong thing for this case (I do not have Mac OS to test it).
Is there a way to get Firefox to tell me what a newline character is? Perhaps some kind of built-in utility function? I use these new lines in text files that my extension writes, and I want to use a specific platform so that the files look appropriate on different systems.
Update (2-13-2013): Thus, when I start the call to the navigator.platform.toLowerCase() function on Mac-mini (OS X), I get the output value of macintel . This will cause my function to return \r instead of \n , as it should.
javascript firefox newline firefox-addon
Jonah bishop
source share