As far as I know, it's not something you do from HTML, but once viewing the file you can right-click and Save as should be an option. I think automatic downloading on following a link is only for files that the browser doesn't know how to display (eg. zip files).
It is not about file type, I am using it for pics, txt, html, etc., which browser can display for sure - it is just about browser type / settings / flags if that download attribute starts download on click or not, as far as i know. I am using chrome, and if you not block download or multiple files download, it works as it should for any file type.
Oh, because I have download enabled... it just keeps redirecting the tab from my "test.html" to "file.extension".
Whats the code? Never seen any other behavior in Chrome than I've written above. Maybe some chrome flags or extension is messing with it, else it works like this - used it few times and it works and worked while ago when i were testing it to be sure :-)
Here's the code:
<!-- Before you say it, this path does exist -->
<a href="path/myfile.png" download>download the file</a>
<!-- when clicked it just redirects me, as I've stated -->
Hopefully this can help you and me understand the issue more.
I got this before, I meant u link real use case where it does not work.
Again, this should work, and works for me.
"Before you say it, this path does exist" -> I am not saying anything, because it even doesn't matter, u can use nonexistent file and it will try to download it.
Drop it into console here and tell me what it does:
const a = document.createElement("a");
a.href = "dev.to/some.png";
Ok, well this works, can you explain what's going on behind the scenes, like what relationship does href and download have?
like is, href the path, and download is the file.... or what?
Thank you so much!
Would be better to show where it does not work for u to find the problem.
Download is just attribute which tells browser to download href link target, and its value is just optional name u want it to have when it is downloading, that's pretty much everything what I have read about it and do not know about any magic behind this, since it worked for me like this exactly:-)
Maybe there are some other solution to google, but i do not know much more, i guess.
Well thanks for your insight!
Have a great day!
Is there any way to get around this because I really need to support the downloading of a few files and I have found nothing on this after checking W3SCHOOLS and sifting through StackOverflow...
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.