-8

I have a a tag with href inside. When link is clicked a wanna download a file from my server. How can I do this. Here is my tag

"    <a href=\""+ downloadPDF("xxx","xxx") +"\">

downloadPDF is a method which starts the download, but how to make the href link call this method?

Mykremin
  • 23
  • 1
  • 6

2 Answers2

1

Download file when clicking on the link (instead of navigating to the file).

Refer this site : w3schools-download

Eg:

<!DOCTYPE html>
<html>
<body>


  <a href="https://www.w3schools.com/images/myw3schoolsimage.jpg" download>
     <img border="0" src="/images/myw3schoolsimage.jpg" alt="Click here to  Download" width="104" height="142">
  </a>

</body>
</html>
Alsamil Mehboob
  • 384
  • 2
  • 6
  • 24
0

You need to use the download attribute in your anchor tag.

Check this https://www.w3schools.com/Tags/att_a_download.asp.

You can also try onclick.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Malar
  • 163
  • 4
  • 17