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

179
Views
¿Cómo hago un botón que descargue un archivo?

Estoy intentando crear un botón que descargue un archivo de imagen al presionarlo, pero lo que hice solo me llevará al archivo en sí.

HTML:

 <button onclick="file()">Click me, i'll download an image</button>

JavaScript:

 function file() { const anchor = document.createElement("a"); anchor.href = "dingus.png"; anchor.download = "dingus.png"; document.body.appendChild(anchor); anchor.click(); }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Aquí está, no olvide eliminar el elemento adjunto.

 function download(url) { const anchor = document.createElement('a') anchor.href = url anchor.download = url.split('/').pop() document.body.appendChild(anchor) anchor.click() document.body.removeChild(anchor) }
about 4 years ago · Juan Pablo Isaza Report

0

la ruta de descarga debe estar en la ruta HTTP, entonces solo funcionará. local que no funcionará

Ejemplo

 function file() { const anchor = document.createElement("a"); anchor.href = "http://www.exampleApiPath.com/dingus.png"; anchor.download = "http://www.exampleApiPath.com/dingus.png"; document.body.appendChild(anchor); anchor.click(); }
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!