Home > Article > Web Front-end > Detailed introduction to the usage of #include file in html
This article mainly introduces the usage of #include file in html. I personally feel that the tutorial is pretty good and suitable for beginners. Friends who need it can refer to it.
There are two files a.htm and b.htm. In the same directory, the content of a.htm is as follows
The code is as follows:
<!-- #include file="b.htm" -->
The content of b.htm is as follows
Today: Rain 31 ℃ ~ 26 ℃ df250b2156c434f3390392d09b1c9563 Tomorrow: Thunder shower 33 ℃ ~ 27 ℃
Open a directly in the browser, nothing is displayed. Later I found out that the include is SSI (Server Side Include), include is not supported in HTML. Then change a.htm to a.aspx, and publish the page on iis, and then you can see the content in a.aspx. If you want to achieve this effect in html, you can use the iframe tag. I found an example directly on the Internet as follows:
The code is as follows:
<iframe frameborder=0 border=0 width=300 height=300 src="b.htm" mce_src="b.htm"></iframe>
html #include file usage
Parameters
PathType
The path type of FileName. The path can be one of the following types:
Path type Meaning
File The file name is the relative path to the directory where the document with the #include command is located. The included file can be in the same directory or a subdirectory; but it cannot be in a directory above the page with the #include command.
Virtual filename The full virtual path to the virtual directory on the Web site.
FileName
Specify the file name to include. FileName must include the filename extension, and the filename must be enclosed in quotation marks (").
Notes
Files containing #include commands must use a file extension that maps to the SSI interpreter ; Otherwise, the Web server will not process the command. By default, the extensions .stm, .shtm, and .shtml are mapped to the interpreter (Ssinc.dll). You can modify the default extension mapping if Internet Services Manager is installed. and add new mappings. See Setting Application Mappings. Included files can have any file extension, but it is recommended to give them the .inc extension.
46991b37b4bd25ecca1ec04b7eee0cd6
7e86e41bc833f2013280903828a541af
49ba6664846bac9373b62d3ba1c724c5
cf0fb08b619dafcda7e1227211f1ddf0
include file and include virtual. Difference
1.#include file includes the relative path of the file, #include virtual includes the virtual path of the file.
2. In the same virtual directory, 4d1269ca3231c6cb67568f997d439ea1 and fc3cbaeb5412f3634f97c799a077e22e have the same effect, but assuming the virtual directory is named myweb, then 657e9b5c4b0d3dc22bb924a429a545b4 can also be debugged, but we know that 7e76f0cfc671ee7d802bffaca82d533d will definitely report an error.
3. If There are two virtual directories myweb1 and myweb2 under a site. There is file file1.asp under myweb1 and file file2.asp under myweb2. If file1.asp wants to call file2.asp, then write this in file1.asp: eec58982a352f0b7e084bc045cd1ac19, in this case it is impossible to use #include file, use 9d6786d989eefa1acda063d25bc0dad0An error will be reported. On the contrary, the same is true for including the files in myweb1 in the files of myweb2. If the included file is under a folder, just add the folder to the virtual path.
4. Whether you use #include file or #include virtual, use "/" or "/" in the path, or use the two interchangeably, it will not affect the compilation effect, and the program will execute smoothly.
5. The above situation does not apply to mutual calls between two site files, and within the same site, d0421cdf18ceb6116e5b7dc8fa6cee50 and bd250b962738d8fd39c38fadde91e133 is equivalent, but assuming the site is named website, using aad10bbb1f308aaf99ecdad05d4eaddf is wrong.
For more detailed introduction to the usage of #include file in html, please pay attention to the PHP Chinese website!