I have an header.html file which I want to include in all my HTML files, how I could do it?
My header.html code:
<html>
<header id="header" class="header">
<--code-->
</header>
</html>
In my html I have tried:
<body>
<!--#include file="layout/header.html" -->
</body>
And also using js:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script>
$(function () {
$("#header").load("layout/header.html");
});
</script>
</head>
<body>
<div id="header"></div>
</body>
I tried this: Include another HTML file in a HTML file
But it does not work for me, header's content does not show. What can be the problem? I tried main.html inside XAMPP and also out it. What I explained before work in Firefox, but not in Chrome, why? When I publish the web, header.html will not load in Chrome browser?
Chrome console error: jquery.min.js:2 Access to XMLHttpRequest at 'file:///C:/.../header.html' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.