below i wanted to create one nav bar for multiple html pages for ease of use .. using JS it gives error ..it seems weird to me,also i wanted to use same method for footer as well
Access to XMLHttpRequest at 'file:///C:/Users/saad/Desktop/myhome-real-estate-free-web-template/navbar.html' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https
fetch('navbar.html')
.then(res => res.text())
.then(text => {
let oldelem = document.querySelector("script#replace_with_navbar");
let newelem = document.createElement("div");
newelem.innerHTML = text;
oldelem.parentNode.replaceChild(newelem,oldelem);
})
<body>
<div id="wrapper" class="home-page">
<header>
<div id="nav-placeholder">
</div>
<script>
$(function(){
$("#nav-placeholder").load("navbar.html");
});
</script>
</header>
</body>
and my navbar.html code below:
<!DOCTYPE html>
<html lang="en">
<div class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html"></a>
</div>
<div class="navbar-collapse collapse ">
<ul class="nav navbar-nav">
<li class="active"><a href="index.html">Home</a></li>
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">About Us <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="about.html">Company</a></li>
<li><a href="#">Our Team</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Investors</a></li>
</ul>
</li>
<li><a href="services.html">Services</a></li>
<li><a href="projects.html">Projects</a></li>
<li><a href="pricing.html">Pricing</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
</div>
</div>
</html>
is there a way to solve this? cux i can’t figure out the problem
thanks in advance