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

281
Visualizações
Custom the downloaded file name and prevent number adding in js

I have following simple code for downloading file.

let text = 'download'
function make(){
    const data = new Blob([text],{ type: 'type: "text/plain"' })
    document.querySelector('a').download = 'untitle'
    document.querySelector('a').href = window.URL.createObjectURL(data);
}
make()
<a download>Download</a>

Broswer (in chrome not sure about other broswer) will automatically specify the number for the second or more time of downloading a same name file.

Example:

first time download: untitle.text

second time download: untitle(1).text ......

Is it possible to prevent the browswer of this behavior from happening ?

Thanks

You could try in https://jsfiddle.net/yapb2xus/1/

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

0

You just can't, that's the default behavior for most of the browsers and almost all OSes because you can't have two files with the same name.

Since chrome (and firefix I think) automatically save the file in a default path, in the first time the file untitle.text will not exist and will be saved with original name. At second tryz the file will exist on default download path, so the browser automatically add a sufix to it.

What you can try is to create your own sequence, adding a timestamp or something else to the name at every click on the link.

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