Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > show a txt-file in Browser

Reply
Thread Tools

show a txt-file in Browser

 
 
Martin Nadoll
Guest
Posts: n/a
 
      10-22-2003
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


 
Reply With Quote
 
 
 
 
Matthias Gutfeldt
Guest
Posts: n/a
 
      10-22-2003
Martin Nadoll wrote:
> 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

 
Reply With Quote
 
 
 
 
Jukka K. Korpela
Guest
Posts: n/a
 
      10-26-2003
"Martin Nadoll" <(E-Mail Removed)> wrote:

> 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).


--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html


 
Reply With Quote
 
Toby A Inkster
Guest
Posts: n/a
 
      10-27-2003
Jukka K. Korpela wrote:

> http://www.cs.tut.fi/~jkorpela/TSV.html


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

--
Toby A Inkster BSc (Hons) ARCS
Contact Me - http://www.goddamn.co.uk/tobyink/?id=132

 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      10-27-2003
Toby A Inkster <(E-Mail Removed)> wrote:

>> http://www.cs.tut.fi/~jkorpela/TSV.html

>
> 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.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html


 
Reply With Quote
 
sumanvarma sumanvarma is offline
Junior Member
Join Date: Mar 2008
Posts: 2
 
      03-22-2009
Put the text you read from the file in <PRE> tag.
Code:
document.getElementById('divlog').innerHTML = "<pre>"+http.responseText+"</pre>";
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>
Quote:
Originally Posted by 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
show calendar show clock tony Cisco 1 09-18-2006 07:13 AM
show all files in the directory, but how to show directory control?? strutsng@gmail.com HTML 1 09-30-2005 07:32 AM
TO show or NOT to show Matt ASP .Net 1 05-02-2005 09:07 PM
to show image or to show flash Disco Octopus HTML 7 05-14-2004 06:27 AM
Command "show run" does not show all interfaces Peter Jonas Cisco 3 01-05-2004 12:13 AM



Advertisments