Output content of a text file on a web page
18,304
You can simply use an iframe
if both the HTML file and the source file are local:
<html>
<head>
<title>Example</title>
</head>
<body>
<iframe src="the-file.txt">
</iframe>
</body>
</html>
Author by
tsionyx
Linux, Rust, Python, bash, bike, roller blades, raising the bar
Updated on June 05, 2022Comments
-
tsionyx almost 2 years
I have an offline html file that contains documentation and I have to output content of text file (in my case it is source code). Is there a way to include content of this file to html page, using only client-side feature (HTML itself or JS)?
Index.html
<html> <head> <style> p.source_code { font-family:"Courier New" } </style> </head> <body> <p> Some content </p> <p class="source_code"> <!-- place for output content of file main.cpp --> </p> </body> </html>
main.cpp
#include <stdio.h> int main() { printf("Hello World"); }
I want my page in browser looks like
Some content #include <stdio.h> int main() { printf("Hello World"); }
-
PeeHaa over 11 yearsUhhhhhm. From my answer: "if both the HTML file and the source file are local". It will only request the local machine. @jasonjifly Or am I missing something?
-
jasonjifly over 11 yearsYeah, if the html file is local, src can be set to local file.