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

270
Visualizações
Javascript .innerHTML; Issue

Okay for a little background I am creating an HTML email signature generator for a client and have run into an issue multiple times. I created a function that allows the user to download the file as a.html so they may install it into their email platform of choice. The problem I am running into a lot is for some reason when using # anywhere in the index.html file it seems like the code stops there when downloading. I assume the # is somehow interfering with the.innerHTML; making it stop for some reason.

I will attach my codepen.io bare in mind there isn't much CSS as I have just started on this and wanted to get the functionality working before making the signature look nice.

link: https://codepen.io/andrewnyrivera/pen/XWaELwL

/* DOWNLOAD! */
    function download() {
      var filename = document.getElementById("filename").value;
      var a = document.body.appendChild(document.createElement("a"));
      a.download = filename + ".html";
      a.href =
        "data:text/html," + document.getElementById("content").innerHTML; // Grab the HTML
      a.click(); // Trigger a click on the element
    }

Also here is an image of how the code is cut off, you can see this in inspect element after you download the file. enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I have figured it out!!!! Thank you to those who have helped guide me! I did some research based on what I was told about the UTF-8 not allowing # symbols and that the # symbol fragments the URL. I ended up putting the "document.getElementById("content")" as a variable and then did "encodeURIComponent(content)". I am not 100% sure why it works but will find out. I assume it encodes it to where the # is no longer there until decoded back to # there for not fragmenting the URL.

function download() { 
  var filename = document.getElementById("filename").value; 
  var content = document.getElementById("content").innerHTML; 
  var a = document.body.appendChild(document.createElement("a")); 
  a.download = filename + ".html"; 
  a.href = "data:text/html;charset=utf-8," + encodeURIComponent(content); 
  a.click(); // Trigger a click on the element
}

Thank you to those who help!

Best,

Andrew

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