Can HTML code be attached to an HTML page like a CSS file?
Yes, he can using frames. Not recommended.
Example:
<frameset cols="10%,90%">
<frame src="navigation.html">
<frame src="content.html">
</frameset>
This code will allow you to reuse the contents of the navigation.html file. Any links clicked on the content.html page would change the content of this frame and the navigation would remain as it is.
The use of frames has many disadvantages (search engine issues, usability, linking, scrolling, etc.) and should not be considered on modern websites (except in very rare cases).
a source to share
Not in plain HTML, no. (Unfortunately)
As Gregory says, you can look at Server Side Includes - they are parsed by the web server.
Alternatively, if you have PHP, you can do include()
:
<?php include "header.html"; ?>
a source to share
You can look at SSI (from the server side) :
Server Side (SSI) is a simple, interpreted server side scripting language used almost exclusively for the Internet. The most common use of SSI is to include the content of one or more files in a web page on a web server.
Also consider:
However, while HTML allows the direct inclusion of CSS files, JavaScript, and images in a web page, it has never allowed HTML to be directly included. There are several tricks for this, each with their own problems. These include:
- Using an IFrame that includes content in a well-defined, fixed size area
- Convert HTML code to JavaScript program that inserts HTML into the DOM.
- Using JavaScript with Ajax to Load Html. Internet Explorer generally prevents this from working directly from the file system due to security concerns.
a source to share
Not possible with pure html if you are using a server-side language, however there is usually such a function available , for example in PHP, is there or to include files. include
require
PHP example:
include ('file.html');
I would recommend that you go to the first (server-side) approach if you are using a server-side language.
a source to share
I don't think this is possible with just HTML, you can get away with it if you use a little JavaScript ... of course if JavaScript is disabled your site won't work.
However, do you think you are using a scripting language like PHP? You can include
html page anytime you want, you only need to change / save one file.
a source to share