Forum Moderators: open
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
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.
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.
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
text/plain to fix the problem) or is it a static file?
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