Hi ,
Can HTML code be attached to HTML page like CSS file ?
So that if part of HTML code is replicated in all pages , I can put it in one file and then easly modify it .
Thanks,
Ahmed.
Hi ,
Can HTML code be attached to HTML page like CSS file ?
So that if part of HTML code is replicated in all pages , I can put it in one file and then easly modify it .
Thanks,
Ahmed.
You may want to have a look at SSI (Server Side Includes):
Server Side Includes (SSI) is a simple interpreted server-side scripting language used almost exclusively for the web. The most frequent use of SSI is to include the contents of one or more files into a web page on a web server.
Also, consider:
However, while HTML allows the direct inclusion of CSS, JavaScript and Image files into a web page it has never allowed direct inclusion of HTML. There are several tricks to achieve this, each with their own problems. These include:
- Using an IFrame, which includes content in a clearly separate, fixed size area.
- Converting the HTML code into a JavaScript program that inserts the HTML into the DOM.
- Using JavaScript with Ajax to load the Html. Internet Explorer will generally not allow this to work directly from the file system due to security concerns.
I don't think it's possible with just HTML, you might be able to get away with it if you use a bit of JavaScript... of course if JavaScript is disabled your site wouldn't work.
That said have you considered using a scripting language such as PHP? You could include
your html page in whenever you desire, you then only have to modify / maintain one file.
Not possible with pure html, if you are using a server-side language however, usually there is such function available, for example in PHP, there is include
or require
functions to include files.
PHP Example:
include ('file.html');
I would recommend you to go with the first (server-side) approach if you are using a server-side language.
Maybe this link will help http://ask-leo.com/how_do_i_include_one_html_file_inside_another.html
Not in plain HTML, no. (Sadly)
As Gregory says, you could look into Server Side Includes - they are parsed by the Web Server.
Alternatively, if you have PHP, you can do an include()
:
<?php include "header.html"; ?>
Yes it can, using frames. Not recommended though.
Example:
<frameset cols="10%,90%">
<frame src="navigation.html">
<frame src="content.html">
</frameset>
This code would allow you to reuse the content of file navigation.html. All links clicked on page content.html would change the content of that frame, and the navigation would stay as it is.
Using frames has many disadvantages (search engine problems, usability, linking, scrolling etc.) and shouldn't be considered in modern web sites (except on very rare occasions).