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

141
Visualizações
Google chrome open image files instead of downloading it

I am trying to download a file by clicking on a link. But every time, if it is something chrome can open (such as an image) instead of downloading the file, it opens it in the new tab. What should I do to prevent it from opening the file and downlaod it? Here is my code

        const downloadElement = document.createElement('a');
        downloadElement.href = data;
        downloadElement.target = '_blank';
        downloadElement.download = data.split('/').pop();
        document.body.appendChild(downloadElement);
        downloadElement.click();
        document.body.removeChild(downloadElement);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

No need to apped link tag in body tag. Try below code it's work for me.

In data you need to pass base64 code. other wise it open in new tab !

const downloadElement = document.createElement('a');
downloadElement.download = data.split('/').pop();
downloadElement.href = data; 
downloadElement.click();
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