Forum Moderators: open

Message Too Old, No Replies

txt file in HTML

TXT in HTML

         

rsennat

6:12 pm on Nov 14, 2005 (gmt 0)



Hi All,

How do I display a .txt file in a HTML page.

I have a HREF to a .txt file and when i click on that it is not diplaying the contents, but throws an error.

So how do i display its contents in a HTML page in the browser, thru the A HREF link.

Thanks
rsennat

music_man

8:13 pm on Nov 14, 2005 (gmt 0)

10+ Year Member



Hi

You can't display a text file using straight HTML unless you use frames I think.

If you use serverside scripting such as php then you can.

Another way to include txt files is to call it using a javascript - like:

Put this in the body of your HTML:

<script language="javascript" src="text.txt"></script>

Then create a new text file in the same folder as your html file called text.txt and put this in it:

document.write('Your text file');

Open the HTML file in your browser and it should display the text "Your text file" (assuming you have javascript turned on).

Make sure you don't delete the document.write(''); as it will make the script not work.

kaled

12:19 am on Nov 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure what you mean but...

If you enter www.google.com/robots.txt in the address bar, the text file will be displayed in the browser window. Similarly, if you were to create a link thus <a href="www.google.com/robots.txt" target="_blank">Test</a> clicking the link would open a new window and display the file.

Kaled.

rsennat

1:02 pm on Nov 21, 2005 (gmt 0)



hi,
i could view the link u have given in google to open a .txt file in the browser.

but when i tried opening a simple tmp.txt file which is in the apache server, cgi-bin folder of mine, Error 500 - internal server error is thrown.

whether any other settings has to be changed?
i gave full permissions to the file.

any suggestions / solutions?

desperately i need this to be solved.
thx
rsennat

peco

12:04 am on Nov 22, 2005 (gmt 0)

10+ Year Member



Please excuse my ignorance here as I am really no expert, but why do you need to link to a text file?
If you want to have a printable text version, can't you just make a word doc or even a pdf version and link to that?

I'm not trying to be facetious in any way, just curious.

kaled

12:15 am on Nov 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I imagine the problem is caused by the .txt file being located in the cgi-bin. I presume that the text file is created by a cgi-program (perl?). I suggest, therefore, you create the file outside the cgi-bin, it should then be accessible.

Kaled.

encyclo

1:35 am on Nov 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think kaled is spot on - it will be a mime-type issue because the text file is stored within a cgi-bin which has the default file type set as a script. Are you generating the text file with a script (in which case you can send a mime-type header of
text/plain
to fix the problem) or is it a static file?

energylevel

2:11 am on Nov 22, 2005 (gmt 0)

10+ Year Member



You need to use SSI ....

rsennat

7:35 am on Nov 22, 2005 (gmt 0)



hi encyclo, kaled,

yep. i am having a static .txt file in the cgi-bin folder and trying to access it from the browser.

so then how can i view the static .txt files in this folder?

thanks
rsennat

kaled

11:35 am on Nov 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just a wild guess... you could try clearing the execute attribute for the file.

If that doesn't work, you could write a script to echo the text file - seems like overkill though.

Kaled.