Say I have a text file (test.txt) that contains only the following line:
假设我有一个只包含以下行的文本文件(test.txt):
<h1>Text text text text text</h1>
Is there any command that I can call the contents from this text file in an HTML document, so the contents in the text file imports where the call is made, every time the side shows?
是否有任何命令可以在HTML文档中调用此文本文件中的内容,因此文本文件中的内容会在每次显示时进口调用的位置?
Example: ?????"/test.txt"?????
3 个解决方案
#1
3
I believe you mean to ask whether there exists a "command" in HTML which allows you to include a file.
我相信您的意思是询问HTML中是否存在允许您包含文件的“命令”。
In pure HTML by itself there does not, but the Apache server-side includes does provide such a directive:
纯HTML本身没有,但Apache服务器端包含确实提供了这样的指令:
<!--#include virtual="./test.txt" -->
You will need to enable SSI processing by your webserver. In Apache, you'd typically call your file .shtml
or something like that.
您需要通过Web服务器启用SSI处理。在Apache中,您通常会调用您的文件.shtml或类似的东西。
#2
1
What you're looking for is the concept call "Server Side Includes". Different servers will do this different ways, so you'll need to look at what your server provides.
您正在寻找的是概念调用“服务器端包含”。不同的服务器将采用不同的方式,因此您需要查看服务器提供的内容。
#3
1
Not with pure HTML, but you can with PHP (and almost every other server side language):
不是纯HTML,但你可以使用PHP(以及几乎所有其他服务器端语言):
<?php include("test.txt"); ?>
Or you can do it in a roundabout way with JavaScript if the file is part of the website, you're actually running a web server, and you're not worrying about older browsers:
或者,如果文件是网站的一部分,你可以用迂回的方式使用JavaScript,你实际上是在运行一个Web服务器,而且你不必担心旧的浏览器:
<script type="text/javascript">
var ajaxRq = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
ajaxRq.open("GET", "test.txt", false);
ajaxRq.send(null);
document.write(ajaxRq.responseText);
</script>
#1
3
I believe you mean to ask whether there exists a "command" in HTML which allows you to include a file.
我相信您的意思是询问HTML中是否存在允许您包含文件的“命令”。
In pure HTML by itself there does not, but the Apache server-side includes does provide such a directive:
纯HTML本身没有,但Apache服务器端包含确实提供了这样的指令:
<!--#include virtual="./test.txt" -->
You will need to enable SSI processing by your webserver. In Apache, you'd typically call your file .shtml
or something like that.
您需要通过Web服务器启用SSI处理。在Apache中,您通常会调用您的文件.shtml或类似的东西。
#2
1
What you're looking for is the concept call "Server Side Includes". Different servers will do this different ways, so you'll need to look at what your server provides.
您正在寻找的是概念调用“服务器端包含”。不同的服务器将采用不同的方式,因此您需要查看服务器提供的内容。
#3
1
Not with pure HTML, but you can with PHP (and almost every other server side language):
不是纯HTML,但你可以使用PHP(以及几乎所有其他服务器端语言):
<?php include("test.txt"); ?>
Or you can do it in a roundabout way with JavaScript if the file is part of the website, you're actually running a web server, and you're not worrying about older browsers:
或者,如果文件是网站的一部分,你可以用迂回的方式使用JavaScript,你实际上是在运行一个Web服务器,而且你不必担心旧的浏览器:
<script type="text/javascript">
var ajaxRq = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP");
ajaxRq.open("GET", "test.txt", false);
ajaxRq.send(null);
document.write(ajaxRq.responseText);
</script>