-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
31 lines (28 loc) · 1.04 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
document.addEventListener("DOMContentLoaded", function () {
// Fetch and insert the common navigation bar
fetch("/html/navbar.html")
.then(response => response.text())
.then(html => {
document.getElementById("navbar-container").innerHTML = html;
// Highlight the active tab
highlightActiveTab();
});
// Fetch and insert the common footer
fetch("/html/footer.html")
.then(response => response.text())
.then(html => {
document.getElementById("footer-container").innerHTML = html;
});
});
function highlightActiveTab() {
// Get the current page's filename
const currentPage = window.location.pathname.split('/').pop();
// Find the corresponding nav link and add the 'active' class
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
const linkPage = link.getAttribute('href').split('/').pop();
if (linkPage === currentPage) {
link.classList.add('active');
}
});
}