Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing a text document into HTML

Tags:

html

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

like image 694
maasha Avatar asked Oct 05 '11 08:10

maasha


3 Answers

I realize the question is old, but this is for reference for people that later come to this question. I often use the embed tag. It was introduced in HTML5, and isn't ugly like iframes. You will still need to specify width and height, but I suggest doing so with css.

<embed src="test.txt">

Notice, the embed tag is open ended. The embed tag is supported in all major browsers.

like image 180
Kuuchuu Avatar answered Oct 10 '22 12:10

Kuuchuu


as you said, another file is another document, so you'll have to use something that allows you to display inline documents: the <iframe> (see wikipedia for more info)

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

if this isn't what you want (frames are... ugly), the other ways to do semething like this is a server-side include or load the document into any element with javascript/ajax (with jQuery, for example).

like image 33
oezi Avatar answered Oct 10 '22 12:10

oezi


Most similar is iframe

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

P/S: Most flexible solution is using JavaScript (How to read from file)

like image 33
Alexander Molodih Avatar answered Oct 10 '22 12:10

Alexander Molodih