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?
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.
Using HTML <iframe> tag.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With