I made a simple web app which lets you edit .txt
files. The .txt
files are loaded into a <textarea>
using jQuery-Ajax (in this case, $.load
). Then, you can click 'save' and the file is saved using PHP fwrite()
This all works fine in modern browsers, tested in Chrome and Safari. However, when I tried it in Internet Explorer 8, it failed. The problem is that it doesn't register new lines. .txt
files that already had new lines didn't keep the new lines when $.load
ed into the <textarea>
. When the files were saved, they saved without the new lines so when opened in a modern browser everything was jumbled up!
IE support is a key part of this web app, and this issue has been with me for a long time... I haven't found any solution yet despite a lot of research.
If you want to look at the code, the URL is www.scriptr.net
But really, the key bit is just:
$('p').load('somefile.txt');
var contents = $('p').html();
$('textarea').val(contents);
and then when the save button is clicked, the textarea is part of a form submitted to a PHP script which uses fwrite()
s it.