English 中文(简体)
我怎么能有一个索引.html网页,该网页有所有其他html网页的主角,因此,我可以防止可疑的代码。
原标题:How can I have a index.html page that has all the head tags for all the other html pages so I prevent dubble code

Let say I usee app.js or a bootstrap cdm link for all my html pages but I dont want to add it to every single page. How can I make a index.html that includes it so all the other html pages first loads the index.html head and then its own head. I use javascript for my project.

I tried to search it upp but none of the questions were the same as mine. My school project used this method so I thought this was a good idea but I dont know how to fix it.

问题回答

你们将需要创建一份html文件,把你想要的链接存放在后面的网页上,例如头.html档案中,然后把你认为必要的链接和其他内容放在头上,例如,我可以把char子放在前面,并观看花板和CDN连接网。

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">

随后,在你希望把这些联系纳入各自负责人的网页上,你可以把文字标签放在各自的主角内,或把内容放在与本法典有关的机构内:

document.addEventListener( DOMContentLoaded , async () => {
    try {
         const response = await fetch("head.html");
         const headContent = await fetch("head.html").text();
         const headElement = document.querySelector("head");

         headElement.insertAdjacentHTML("afterbegin", headContent);
    } 
    catch(error) {
         console.log("Error fetching head.html", error);
    }
});

如果你想避免在你的超文本档案中明确写法,那么你也可以把该守则放在自己的Java文本档案中。

现在,每一页都使用这一信息。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签