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

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

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 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!