Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
Can't make <header> and <footer> shared across pages

I tried to put <header> and <footer> in external files. In the console, the code outputs fine, but then the code returns undefined.

Footer HTML:

<footer id="footer" class="footer mt-auto py-3 bg-light">
<div class="container">
    <div class="col-12 text-center">
        <a style="text-anchor: middle">© 2021 AlexInCube</a>
    </div>
</div>

main.html

<script>document.write(importHTMLdata("content/basement.html"))</script>

scripts.js

function importHTMLdata(path){
    $.get(path, function(html_string)
    {
        console.log(html_string)
        return html_string;
    });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It is NOT recommended to have document.write - it will wipe the page if executed after page load.

Just have this in your js file

$(function() { // on page load
  const importHTMLdata = path => { // define a function taking a path
    $.get(path, function(html_string) { // get the path
      $("body")[path.indexOf("footer") != -1 ? "append" : "prepend"](html_string); // if footer call $("body").append, if not call $("body").prepend
    });
  }
  importHTMLdata("content/header.html"); // load header
  importHTMLdata("content/footer.html")  // load  footer
});
<script src="scripts.js"></script>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda