Reputation: 305
I'm making a header using HTML and Bootstrap and I want the header to appear on all pages of my site. Is there a way to do something similar to a CSS style sheet but instead of CSS, reusing HTML?
Upvotes: 3
Views: 2855
Reputation:
If you don't want to store jquery, you can use a CDN
<html>
<head>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script>$(document).ready(function () { $("header").load("assets/header.html"); });</script>
</head>
<body>
<header></header>
</body>
</html>
Upvotes: 1
Reputation: 76
The simplest way I believe is to use jQuery.
See jQuery docs here
one.html:
<html>
<head>
<script src="jquery.js"></script>
<script>
$(function(){
$("#header").load("two.html");
});
</script>
</head>
<body>
<div id="header"></div>
</body>
</html>
two.html:
<p> Put your header in here </p>
Upvotes: 5
Reputation: 991
You can use an <iframe>
to change the content that is displayed, and only code the surrounding header/footer/etc. only once. There seems to be some uneasy feelings about using them floating around, so I would do some research on that before I committed to it.
HTML include
is a recent feature you could try as well. Otherwise, it's gonna be good ol' fashioned ctrl-c
ctrl-v
.
Upvotes: -2