开发者

Importing a text document into HTML

开发者 https://www.devze.com 2023-04-10 14:44 出处:网络
I was wondering if there is a HTML element that allows you to incorporat开发者_运维问答e a text file into a HTML document - something ala <pre src=\"test.txt\"\\>?I realize the question is old,

I was wondering if there is a HTML element that allows you to incorporat开发者_运维问答e a text file into a HTML document - something ala <pre src="test.txt"\>?


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.


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)


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).


Not standard HTML.

You might thought want to look to see if your server supports server-side includes although these are often disabled for being a percieved security risk.

You'd then be able to do:

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

In order to get them parsed properly by the server, you may have to give the HTML file a different extension (e.g., .shtml, .shtm) -- this is also specific to a given server's configuration.

Otherwise you'll have to have some dynamic script (CGI, ASP, ASPX, PHP, whatever) to merge the two together serverside.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号