show a txt-file in Browser

M

Martin Nadoll

Hello,

i want to link to mytext.txt, that looks something like:

this;info;is;in;the;first;line
this;comes;in;second;;;
this;is;third;;;;

But browsers dont understand the newline, so everything is in one line.
I can't add <br>-Tags because the file is also needed to import into excel
as comma-separated list.

Are there any ideas for that?

Thanks a lot for any help,
Martin Nadoll
 
M

Matthias Gutfeldt

Martin said:
i want to link to mytext.txt, that looks something like:

this;info;is;in;the;first;line
this;comes;in;second;;;
this;is;third;;;;

But browsers dont understand the newline, so everything is in one line.
I can't add <br>-Tags because the file is also needed to import into excel
as comma-separated list.

Are there any ideas for that?

Hmm... browsers should usually display .txt files 'as is'. Perhaps
there's HTML in the .txt file, and the browser thinks it's HTML? Or
perhaps the server doesn't send the correct MIME type?


However, if you're importing/including this text in a HTML file, you
could use either the PRE element
<http://www.w3.org/TR/html4/struct/text.html#edef-PRE>, or the CSS
white-space property,
<http://www.w3.org/TR/CSS2/text.html#propdef-white-space>


Matthias
 
J

Jukka K. Korpela

Martin Nadoll said:
i want to link to mytext.txt, that looks something like:

this;info;is;in;the;first;line
this;comes;in;second;;;
this;is;third;;;;

Looks a bit odd. But what's the URL? Note that the URL is essential,
not the content only, since the URL reveals what the server announces
about the Internet media type.
But browsers dont understand the newline, so everything is in one
line.

Which newline? You _might_ have a problem with newline presentation
convention in a plain text file (CR vs. LF vs. CR LF).
I can't add <br>-Tags because the file is also needed to
import into excel as comma-separated list.

Of course you cannot use HTML markup in a plain text file - any
correctly behaving browser will treat is plain data.

But how come you refer to a comma-separated list? The character
";" is a semicolon in my book.

I would suggest that you use either comma-separated list or tab-
separated list and announce the media type appropriately. Specifically
I would recommend tab-separated, for reasons explained at
http://www.cs.tut.fi/~jkorpela/TSV.html
Though ideally you should convert the data to a simple HTML table and
make it available in both formats, via separate links (or even insert
the HTML format into a normal HTML page).
 
J

Jukka K. Korpela

Toby A Inkster said:
The table about 80% of the way down the page is screwy. Most of the
rows don't begin with <tr>.

Oops, thanks. The markup was _bad_. Fixed now.
 
Joined
Mar 31, 2008
Messages
2
Reaction score
0
Use <PRE> tag.

Put the text you read from the file in <PRE> tag.
Code:
[B]document.getElementById('divlog').innerHTML = "<pre>"+http.responseText+"</pre>";[/B]
Try this:
Code:
<html>
<head>
  <script type="text/javascript">
    var http = false;

    if(navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      http = new XMLHttpRequest();
    }

    function showFileText(file) 
	{
      http.abort();
      http.open("GET", file, true);
      http.onreadystatechange=function() 
				  {
					if(http.readyState == 4) {
					  document.getElementById('divlog').innerHTML = "<pre>"+http.responseText+"</pre>";
					}
				  }
      http.send(null);
    }
  </script>

</head>
<body>

<form>
  <input type="file" name="datafile" value="" size="100">
  <input type="button" value="Show Text" onClick="showFileText(datafile.value);" />
  <br>
 <div id="divlog" align="left" style="left:10px; top:41px;" ></div>

</form>

</body>
</html>

Martin Nadoll said:
Hello,

i want to link to mytext.txt, that looks something like:

this;info;is;in;the;first;line
this;comes;in;second;;;
this;is;third;;;;

But browsers dont understand the newline, so everything is in one line.
I can't add <br>-Tags because the file is also needed to import into excel
as comma-separated list.

Are there any ideas for that?

Thanks a lot for any help,
Martin Nadoll
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top