making a paragraph in html contain a text from a file
It can be done with HTML <embed>
or <object>
tags, Javascript, or PHP/ASP/other back-end languages.
PHP (as example of server-side language) is the the way I've always done it:
<div><p><?php include('myFile.txt'); ?></p></div>
To use this (if you're unfamiliar with PHP), you can:
1) check if you have php on your server
2) change the file extension of your .html file to .php
3) paste the code from my PHP example somewhere in the body of your newly-renamed PHP file
Get text from .txt and put in html
You can use jQuery's load function.
Here are the steps:
include jQuery script file in your html. You can use CDN
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
Write script to load to text in file to web page. Observe the code bellow:
<div class="pasteHere">
<p id="fileTextHere">text from files/text.txt</p>
</div>
<script>
$('#fileTextHere').load("[file url or location path]");
</script>Give the file path inside load function without
[
]
brackets
Note that if you are passing a system file path in load function it will not work in chrome because chrome only allows files over internet and not on local desktop. Firefox does allow it though.
How to embed a text file inside html?
Since you are already using Jekyll, just use its built-in include mechanism:
{% include stuff.txt %}
Reading content from .txt file into a paragraph tag p /p
You can make a p tag as runat="server" on your aspx page like this
<p runat="server" id="paragraph"></p>
Then in your code behind (aspx.vb file) after reading all your lines do this:
paragraph.InnerText = "Your variable containing the text";
How do I include the contents of a text file into my website?
Just don't read files in js in a web browser.
You can create an API with node.js and then make an http request to get this data.
Once you created the server, just do like that:
const fs = require('fs');
var content;
// First I want to read the file
fs.readFile('./Index.html', function read(err, data) {
if (err) {
throw err;
}
content = data;
// Invoke the next step here however you like
console.log(content); // Put all of the code here (not the best solution)
processFile(); // Or put the next step in a function and invoke it
});
function processFile() {
console.log(content);
}
simple way to display data in a .txt file on a webpage?
Easy way:
- Rename
missingmen.txt
tomissingmen.html
. - Add a single line to the top of
missingmen.html
:<link href="txtstyle.css" rel="stylesheet" type="text/css" />
- Create a file called
txtstyle.css
, and add to it a line like this:html, body {font-family:Helvetica, Arial, sans-serif}
How to use a text file's contents in HTML as text
You could use AJAX:
$.get( "mytext.txt", function( txt ) {
$( "#myParagraph" ).text( txt );
});
You will need to host your HTML from a server, or otherwise it won't work
Related Topics
Valid Content-Type for Xml, HTML and Xhtml Documents
How to Change Content on Hover
Table Headers Position:Sticky and Border Issue
Why Should One Add Id to Their HTML Tags
CSS - Hide Options from Select Menu on iPhone & Safari
Why Is Using the Style-Attribute in HTML Bad
Rectangles Instead of Whitespace in Chrome
Why Won't Tabindex Work with Firefox
3 Column Layout (Fixed, Fluid, Fixed) with Minimum Width
Do HTML5 Script Tag Need Type="Javascript"
What Elements Can a Span Tag Contain in HTML5
How to Include All CSS Kept in a Directory
Floating Elements Are Outside of Containing Blocks
Displaying Elements Other Than Fullscreen Element (Html5 Fullscreen API)
How to Indent All Text in a Paragraph Except the First Line