I have a requirement to get the file from an API which is returning filedata in base64 format. I am adding that to <a href
tag that looks like below
<a id="myFile" href="data:image/png;base64,..." click="downloadFile()">Download File</a>
So I want to trigger filedownload using $('#myFile').click()
which is going to downloadFile()
function, but I can't use location.href as I don't want the page to be redirected.
Is there any alternative for this requirement? Any suggestions would be a great help.
NOTE: I am getting href value dynamically with some ajax response once the link is clicked, initially href is set to # and will be replaced with appropriate downloadable string as above. I want to trigger file download along with the same event that triggered ajax request and not with a separate click event.