最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to embed a text file inside html? - Stack Overflow

programmeradmin0浏览0评论

I've got an index.html file for use with Jekyll and would like the contents of one paragraph in the HTML file to be called from a text file ("stuff.txt") located in the same directory as the index.html file.

Is there a simple HTML command to read in the text, preferably outwith the use of PHP or JavaScript?

I've got an index.html file for use with Jekyll and would like the contents of one paragraph in the HTML file to be called from a text file ("stuff.txt") located in the same directory as the index.html file.

Is there a simple HTML command to read in the text, preferably outwith the use of PHP or JavaScript?

Share Improve this question edited Jul 28, 2018 at 17:55 Nimeshka Srimal 8,9305 gold badges45 silver badges60 bronze badges asked Sep 18, 2014 at 9:44 Jim MaasJim Maas 1,7293 gold badges21 silver badges42 bronze badges 3
  • Take a look at this: stackoverflow.com/questions/6470567/… – Matheno Commented Sep 18, 2014 at 9:46
  • " preferably without the use of PHP or JavaScript?" – danielg44k Commented Sep 18, 2014 at 9:48
  • 1 "outwith" is as valid as "without" :-) – Jim Maas Commented Sep 18, 2014 at 9:50
Add a comment  | 

5 Answers 5

Reset to default 6

If you really do not wish to use js or php, here is a solution. Use the embed tag to embed the text file into your document. Otherwise, you can use an iframe too.

  <embed src="stuff.txt">

Reference Link : http://www.quackit.com/html_5/tags/html_embed_tag.cfm

without php

<iframe src='stuff.txt' scrolling='no' frameborder='0'></iframe>

just tested and it works . Or try it with php as bellow

<iframe src='txt.php' scrolling='no' frameborder='0'></iframe>

and txt.php

<?php
echo file_get_contents("stuff.txt");
?> 

This actually seems to work:

<object width="1000" height="200" data="stuff.txt"></object>

Since you are already using Jekyll, just use its built-in include mechanism:

{% include stuff.txt %}

You need to use PHP or Javascript, but there's an old-fashioned way that you can use called Server-Side Includes:

http://www.htmlgoodies.com/beyond/webmaster/article.php/3473341

You will need to rename your file to index.shtml and write something like:

<!--#include file="stuff.txt" -->

Update per comment: You need to be on a server that supports SSI. From my experience, most shared hosting servers support it, but you might need to ask your host.

发布评论

评论列表(0)

  1. 暂无评论