0

In my html page I want to add footer and header for all the pages

This app need to run by opening the file and not with server running.

I add to my code

fetch('shared/header.html')
.then((response) => {
    return response.text();
})
.then((html) => {
    document.body.innerHTML = html     
});

but I got cors error

Access to fetch at 'file:///D:/projects/javascriptApp/shared/header.html' from origin 'null' has been blocked by CORS policy:

How can I add shared html files into another file with vanilla javascript

24sharon
  • 1,859
  • 7
  • 40
  • 65
  • as I said this file need open by the file location and the browser without any server running – 24sharon Dec 21 '22 at 09:04
  • Do you want any website to be able to read items from your documents folder or hdd? – Chris Dec 21 '22 at 09:06
  • @DreamBold — That's extremely dangerous and people doing that need to be very very careful not to start accessing third party websites with that setting turned on. – Quentin Dec 21 '22 at 09:14
  • Yes, but what he's trying is dangerous as well – DreamBold Dec 21 '22 at 09:15
  • This app is not on the web, its a local project, I cannot run the command because I need any computer that run this html file will see the app with the header and footer, I need just something like Iframe – 24sharon Dec 21 '22 at 09:18

0 Answers0