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

251
Visualizações
Using innerHTML to get a whole page content

I am still a beginner in Javascript and I wondering if I can use innerHTML to post the whole HTML content from another page. I have used innerHTML to just post an HTML code within the same .js page. For example:

I have main.js that contains this

class MyComponent extends HTMLElement {
  connectedCallback() {
this.innerHTML = `<h1>Hello world</h1>`;
  }
}

customElements.define('my-component', MyComponent);

and in the index.html I use this code to implement the main.js

<!doctype html>
<html lang="en">
<head>
<script type="application/javascript" src="js/main.js"></script> 
</head>
   
<body>
    <my-component></my-component>
</body>
</html>

The question is can I include an HTML page instead <h1>Hello world</h1> like header.html to get the whole HTML code from it? if not, Is there any way to do that? Thanks.

Edit: I mean for example if I have a page named footer.html and in that page, I have an h1 ex. "Hello world" And I need to use the same h1 in another page index.html without rewrite it again. Can I make that h1 as a template to use in any other page using javascript? My idea that I was looking for is:

  • Making main.js
  • get h1 from footer.html in main.js
  • import that script in index.html
  • using h1 in index.html I know that I can do that using "include" in PHP but I am just trying to do it by javascript.
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can do that with AJAX. Set an URL for that file and make a get request with AJAX.

Using JQUERY

$.get("file_path.html", function(fileText){});
about 4 years ago · Juan Pablo Isaza Relatório

0

You can try:

document.body.innerHTML

to access page content.

about 4 years ago · Juan Pablo Isaza 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