Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
How to use content from <head></head> on multiple pages in JS

I have a site with a few different pages, I mainly use javascript

How can I load the content from 1 to multiple .html pages within my site

this is some content

<head>
     <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
        <meta name="description" content="Web3 tutorials">
        <meta name="keywords" content="Blockchain, Web3">
        <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
        <script src="https://unpkg.com/moralis-v1@1.11.0/dist/moralis.js"></script>
        <!-- Latest compiled and minified CSS -->
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
        <link href="style/alltoken.css" rel="stylesheet">
        <!-- Latest compiled JavaScript -->
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
        <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
</head>

How can I reuse the content on different html pages without copying it over and over again into every html page

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Hello An droid(nice namelol). Assuming you have a regular website. The fastest way to do this is to change the document type from .HTML, to .PHP

next, create a new PHP document called "whatever-you-want.php"(obviously you can change this filename lol) and in it, place the code you want to copy to other pages. Next, go to those pages and remove the duplicated code and add

<?PHP include("whatever-you-want.php"); ?>

Please note: don't be afraid of the "PHP" extension or filename change. It will still output your code the same way as HTML.

This will now transfer that one code set in that one file, and imports it into the pages that you add that "include" to.

Last note. There are other ways depending on what you are using, but this is probably the fastest and less headache ways to do it.

Good luck.

about 4 years ago · Santiago Trujillo Relatório

0

Use the Fetch API to load external files. See this example:

fetch('header.html')
    .then(response => response.text())
    .then(header => document.head.innerHTML = header);
about 4 years ago · Santiago Trujillo Relatório

0

Without server-side technology like PHP, you have a few options. You should be able to use the HTML <object> tag:

<head>
  <!-- Page-specific tags like title -->
  <object type="text/html" data="headerContent.html"></object>
</head>

Where headerContent.html includes the HTML tags that you'd like to include in your head. You could also include JavaScript that inserts the HTML:

document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeend", yourHTMLString);

Where yourHTMLString is a string literal containing the HTML tags you'd like to include in your head.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda