Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!