function loadInto(id, url) { var el = document.getElementById(id); if (!el) return; fetch(url) .then(function (res) { if (!res.ok) throw new Error(res.status); return res.text(); }) .then(function (html) { el.innerHTML = html; }) .catch(function () {}); } document.addEventListener("DOMContentLoaded", function () { loadInto("header", "./components/header.html"); loadInto("footer", "./components/footer.html"); loadInto("message", "./components/message.html"); });