Example of using #include file in html

Example of using #include file in html
There are two files a.htm and b.htm. In the same directory, the content of a.htm is as follows

Copy code
The code is as follows:

<!-- #include file="b.htm" -->

b.htm content is as follows

Today: Rain 31 ℃~26 ℃ <br />Tomorrow: Thunderstorm 33 ℃~27 ℃

When I opened a directly in the browser, nothing was displayed. Later I learned that include is SSI (Server Side Include) and include is not supported in html. Then I changed a.htm to a.aspx and published the page on IIS. Then I could see the content in a.aspx. To achieve this effect in HTML, you can use the iframe tag. I found an example on the Internet as follows:

Copy code
The code is as follows:

<iframe frameborder=0 border=0 width=300 height=300 src="b.htm" mce_src="b.htm"></iframe>

Usage of #include file in html

parameter

PathType

Type the path to FileName. A path can be one of the following types:

Path type meaning

The file name is a relative path to the directory containing the document with the #include directive. The included file can be located in the same directory or a subdirectory; but it cannot be in the directory above the page with the #include directive.
The virtual file name is the full virtual path to the virtual directory on the Web site.

FileName

Specifies the file names to include. FileName must include the file name extension, and the file name must be enclosed in quotation marks (").

Notes

The file containing the #include directive must use a file extension that is mapped 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). If Internet Services Manager is installed, you can modify the default extension mappings and add new mappings. See Setting up application mappings. Included files can have any file extension, but it is recommended to give them the .inc extension.

Example

<!--The included file exists in the same directory as the parent file. -->
<!-- #include file = "myfile.inc" -->

<!--The included files are located in the script virtual directory. -->
<!-- #include virtual = "/scripts/tools/global.inc" -->

The difference between include file and include virtual

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, the effects of <!--#include file="file.asp"--> and <!--#include virtual="file.asp"--> are the same. However, assuming the virtual directory is named myweb, then <!--#include virtual="myweb/file.asp"--> can also pass debugging, but we know that <!--#include file="myweb/file.asp"--> will definitely report an error.
3. If a site has two virtual directories myweb1 and myweb2, myweb1 contains file file1.asp and myweb2 contains file file2.asp, if file1.asp wants to call file2.asp, then you need to write in file1.asp: <!--#include virtual="myweb2/file2.asp"-->. In this case, it is impossible to use #include file, and using <!--#include file="myweb2/file2.asp"--> will inevitably result in an error. Conversely, the same is true for including files from myweb1 in files in myweb2. If the included file is in 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 both of them interchangeably, it will not affect the compilation effect, and the program will execute smoothly.
5. The above situation does not apply to the mutual calls of two site files, and in the same site, <!--#include file="file.asp"--> and <!--#include virtual="file.asp"--> are equivalent. However, assuming that the site name is website, it is wrong to use <!--#include virtual="website/file.asp"-->.

<<:  SQL implementation of LeetCode (182. Duplicate mailboxes)

>>:  Detailed explanation of the use of Vue mixin

Recommend

Future-oriented all-round web design: progressive enhancement

<br />Original: Understanding Progressive En...

JavaScript to implement mobile signature function

This article shares the specific code of JavaScri...

jQuery implements breathing carousel

This article shares the specific code of jQuery t...

20 CSS coding tips to make you more efficient (sorted)

In this article, we would like to share with you ...

CSS uses calc() to obtain the current visible screen height

First, let's take a look at the relative leng...

MySQL 5.7.21 installation and configuration tutorial under Window10

This article records the installation and configu...

Use IISMonitor to monitor web pages and automatically restart IIS

Table of contents 1. Tool Introduction 2. Workflo...

Introduction to the use of MySQL pt-slave-restart tool

Table of contents When setting up a MySQL master-...

Solution to the problem that Docker container cannot access Jupyter

In this project, the Docker container is used to ...

Linux installation MySQL5.6.24 usage instructions

Linux installation MySQL notes 1. Before installi...

Rhit efficient visualization Nginx log viewing tool

Table of contents Introduction Install Display Fi...

Common repair methods for MySQL master-slave replication disconnection

Table of contents 01 Problem Description 02 Solut...

JS implements random generation of verification code

This article example shares the specific code of ...