show a txt-file in Browser

Discussion in 'HTML' started by Martin Nadoll, Oct 22, 2003.

  1. 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
     
    Martin Nadoll, Oct 22, 2003
    #1
    1. Advertising

  2. 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
     
    Matthias Gutfeldt, Oct 22, 2003
    #2
    1. Advertising

  3. "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;;;;


    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
     
    Jukka K. Korpela, Oct 26, 2003
    #3
  4. Toby A Inkster, Oct 27, 2003
    #4
  5. Jukka K. Korpela, Oct 27, 2003
    #5
  6. Martin Nadoll

    sumanvarma

    Joined:
    Mar 31, 2008
    Messages:
    2
    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>
    
    
    
     
    sumanvarma, Mar 22, 2009
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ko
    Replies:
    2
    Views:
    388
  2. RNDAS

    How to open a txt file in browser

    RNDAS, Apr 26, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    6,302
    Lionel LASKE
    Apr 26, 2005
  3. Replies:
    7
    Views:
    8,947
    David Dorward
    Feb 9, 2006
  4. Sameen
    Replies:
    2
    Views:
    475
    Victor Bazarov
    Aug 29, 2005
  5. Jochen Brenzlinger
    Replies:
    7
    Views:
    5,846
    Roedy Green
    Sep 15, 2011
Loading...

Share This Page