Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply same content to multiple html pages

Tags:

html

I'm new to html and was wondering if there is a way to apply the same content to many html files at once.

For example, if I have many pages, but all those pages have an identical navigation side panel that contains links to all the other pages. Is there any way to change the contents of this side panel without changing it for each individual page? i.e. is there a feature that allows me to make this navigation panel in a separate file, then tell all my pages to include this navigation file?

I know a css file can control the format of many html pages - is there an analogy to this that can control the content of many html pages?

like image 796
xdl Avatar asked Dec 17 '11 23:12

xdl


People also ask

How do I use the same HTML code on multiple pages?

You can store one or more of your JavaScript scripts in a single . js file and access them from multiple HTML pages. Put the script in an external JavaScript file. If you have the script already inside your HTML page, remove all the JavaScript code inside the <script> tag and paste it into a separate file.


2 Answers

You can use PHP to do that. Write the HTML code in PHP file, then add include statement in your HTML. This saves you from having to write same code again and again specially for navigation, etc.

PHP manual explains it.

Hope it helps.

like image 69
Subash Avatar answered Nov 02 '22 17:11

Subash


You can write the common content in javascript file and include it in your html pages using script tag:

<script src="YOUR_FILE.js"></script>

You can use an online HTML to Javascript converter like this one to generate you javascript code.

like image 28
O.Badr Avatar answered Nov 02 '22 17:11

O.Badr