HTML - Display text from a text file
9 posts
Page 1 of 1
In html, is there any way to display some text from a given text file on a webpage? Thanks!
Last edited by Cheatmasterbw on Thu Feb 24, 2011 12:31 am, edited 1 time in total.
You can do it with php - www.codenstuff.com/forum/viewtopic.php?f=38&t=4032
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
You can use JavaScript to access the file:
Code: Select all
<html>
<head>
</head>
<body>
<textarea id="text"></textarea>
<script>
var req = new XMLHttpRequest();
req.open("GET", "file.txt", false);
req.send();
var textarea = document.getElementById("text");
textarea.innerText = req.responseText;
</script>
</body>
</html>
thanks! Also, if there is an error reading the text file, what text would be displayed?
is there a way to make it display no text if there is an error?
Cheatmasterbw wrote:In html, is there any way to display some text from a given text file on a webpage? Thanks!Looks like mandai's got you covered, however let me remind you that html is a markup language (Hence Hypertext Markup Language) if you're unaware of what that means, just Google it, and you should findout.
i guess i should be good with that.
Cheatmasterbw wrote:is there a way to make it display no text if there is an error?Yes you can check the status code with req.status.
9 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023