Я пытаюсь вывести строки текстового файла в div в HTA. Сам текст подходит просто прекрасно, однако линии не переносятся. Вместо этого текст группируется по одной большой строке. Если я печатаю сообщение в msgbox, то появляются правильные, разделенные строки.Многострочный текстовый файл html
function updateTPtally()
{
var fso, appdir, messagefile, ts, messagetext, line;
fso = new ActiveXObject("Scripting.FileSystemObject");
if (MESSAGE_FILE_NAME7.indexOf("\\") == -1) {
appdir = unescape(fso.GetParentFolderName(location.pathname));
messagefile = fso.BuildPath(appdir, MESSAGE_FILE_NAME7);
} else {
messagefile = MESSAGE_FILE_NAME7;
}
try {
// Open the message-of-the-day file as a TextStream.
ts = fso.OpenTextFile(messagefile, 1);
messagetext = "";
while (! ts.AtEndOfStream) {
line = ts.ReadLine();
// If the line contains text, enclose in <p> element;
// otherwise, construct a blank line with a nonbreaking space.
if (line.length > 0)
line = line.replace(/^(.*)$/, "$1");
else
line = "<p> </p>";
messagetext += line;
}
ts.Close();
}
// Construct an error message if an error occurred.
catch(err) {
messagetext = "<p>Can't display the message of the day.</p>"
+ "<p> </p>"
+ "<p>Error <b>0x" + hex(err.number) + "</b><br />"
+ err.description + "</p>";
}
// Update the innerHTML element of the textarea element with the
document.getElementById("TPtallymemo").innerHTML = messagetext;
}
EDIT: Я добавил линию = line.replace (/ \ п/г, "
");
Это похоже на работу, однако первое слово текста. Это мой текстовый файл:
Hello.
This should be line two. And written all in one line.
This should be line three, and also written on one line.
Это то, что печатает в моем пролете:
Hello.
This
should be line two. And written all in one line.
This
should be line three, and also written on one line.
В Windows символ новой строки '\ r \ n'. Вы должны заменить это вместо '\ n'. – Teemu