Pregunta

i'm looking to take some html, mainly the navigation bar and code:

<div id="navbar">
        <ul> 
            <li><a href="">Buy</a></li>
            <li><a href="">Lookbook</a></li>
            <li><a href="">About</a></li>
            <li><a href="">Contact</a></li>

        </ul>
    </div>

and insert it on every page on a given site. how would i do this so that when i make changes it reflects on all the pages, so i don't have to copy and paste the changes on each page.

¿Fue útil?

Solución

  1. Add a empty div on all pages.
  2. Create a common java script function that will insert the above html to those Empty div.
  3. Call that javascript function on all the pages.
  4. This method is good only if you are working with Static HTML pages without any server side script.

Otros consejos

One way is to have your pages in PHP and include a common file into each of them. That would let you make changes to your navbar and all pages would pick them up. It would require changing your pages to PHP and adding appropriate include statements in each though.

Creater a header page! Create a new page with the .php extension. For this example, call it someheader.php

Include the following code in every new .php file between the <html> tags:

<php 
include('someheader.php');
?>

This saves time since it won't be neccessary to retype the same code over and over.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top