Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   HTML (http://www.velocityreviews.com/forums/f31-html.html)
-   -   show a txt-file in Browser (http://www.velocityreviews.com/forums/t155424-show-a-txt-file-in-browser.html)

Martin Nadoll 10-22-2003 08:09 AM

show a txt-file in Browser
 
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



Matthias Gutfeldt 10-22-2003 08:29 AM

Re: show a txt-file in Browser
 
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


Jukka K. Korpela 10-26-2003 05:15 PM

Re: show a txt-file in Browser
 
"Martin Nadoll" <martin@nadoll.de> 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



Toby A Inkster 10-27-2003 09:56 AM

Re: show a txt-file in Browser
 
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


Jukka K. Korpela 10-27-2003 11:12 AM

Re: show a txt-file in Browser
 
Toby A Inkster <UseTheAddressInMySig@deadspam.com> 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



sumanvarma 03-22-2009 08:29 AM

Use <PRE> tag.
 
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



All times are GMT. The time now is 08:54 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.