Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert one HTML file into another HTML file [duplicate]

I am making a huge website, with on all pages a navbar. Is it possible to create the navbar in a .html file and import it into all the other pages, and if so, how?

like image 480
user3032715 Avatar asked Jan 01 '14 11:01

user3032715


People also ask

How do I display another HTML page in a div?

To load external HTML into a <div>, wrap your code inside the load() function. To load a page in div in jQuery, use the load() method.

Which of the following elements would you use to display another HTML document inside one HTML document?

Using HTML <iframe> tag.


1 Answers

You can do this with HTML alone using Server Side Includes. Simplest example:

index.html

<html><head><title>Test</title></head>
<body>
    <!--#include file="navbar.shtml" -->
</body>
</html>

navbar.shtml

<ul class="nav">
    <li><a href="/">Home</a></li>
    <li><a href="/about">About</a></li>
</ul>

What you should never do is use framesets or iframes to do this. https://stackoverflow.com/a/15938545/822711

Please note, this will not work using the file:// protocol, it needs to run on a web server as it would in a live environment. This could be on a private or public server, or localhost using a server running on your computer such as wamp.

like image 184
Popnoodles Avatar answered Sep 23 '22 06:09

Popnoodles