Files
gateway-gamers.net/src/main.js
T

22 lines
629 B
JavaScript
Raw Normal View History

function loadHTML(file, elementId) {
fetch(file)
.then(r => r.text())
.then(html => {
document.getElementById(elementId).innerHTML = html;
if (elementId === 'header') highlightActiveNav();
})
.catch(err => console.error('Error loading:', file, err));
}
function highlightActiveNav() {
const current = location.pathname.split('/').pop() || 'index.html';
document.querySelectorAll('#header a[href]').forEach(link => {
if (link.getAttribute('href') === `/${current}`) {
link.classList.add('active');
}
});
}
loadHTML('/header.html', 'header');
loadHTML('/footer.html', 'footer');