Import a text document into HTML

I was wondering if there is an HTML element that allows you to include a text file in an HTML document - something ala <pre src="test.txt"\> ?

+4
source share
4 answers

I understand that the question is old, but this is for people who later came to this question. I often use the embed tag. It was introduced in HTML5 and not as ugly as an iframe. You still need to specify the width and height, but I suggest doing this with css.

 <embed src="test.txt"> 

Note that the embed tag is open. The built-in tag is supported in all major browsers.

+12
source

Most similar iframe

 <iframe src="test.txt" width="100%" height="300"> </iframe> 

P / S: the most flexible solution uses JavaScript ( How to read from a file )

+1
source

as you said, another file is a different document, so you will need to use something that allows you to display inline documents: <iframe> (see wikipedia for more information)

 <iframe src="test.txt" height="200" width="200"> Your Browser doesn't support Frames. </iframe> 

if this is not what you want (frames ... ugly), other ways to do it as the server side of include or load the document into any element using javascript / ajax ( with jQuery , for example).

+1
source

Custom HTML.

You might want to see if your server supports the server side , although they are often disabled in order to be perceived as a security risk.

Then you can:

 <pre> <!--#include virtual="text.txt" --> </pre> 

For proper analysis by the server, you may need to provide the HTML file with another extension (for example, .shtml, .shtm) - this also applies to this server configuration.

Otherwise, you will need a dynamic script (CGI, ASP, ASPX, PHP, any) to combine the two servers.

+1
source

All Articles