Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The download attribute in anchor tag is not working in HTML

<!DOCTYPE html>
<html>
    <head>
        <title>
            Hello
        </title>
    </head>
    <body>
        <!--Anchor Tag-->
        <a href="./HG.jpg" download>Download image</a>
        <a target="_blank" href="./HG.jpg" download>Download image</a>
    </body>
</html>

I am running this in Chrome browser but the file is not being downloaded. The file is in the same folder as the html file.
I also tried to go through the previously answered same question but it still isn’t working.
The image opens in both cases; the one where I have used target attribute opens the image in a new tab and the one without target attribute opens in the same tab. But after that nothing happens. The download is not initiated. I even checked the browser download settings but they are not the reason for this.
I would really appreciate if someone can guide me how to make this work.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It’s the same issue as the not-working fetch() – it’s a security feature that the browser treats two file:/// paths as different origins. And because the download attribute only works on resources of the same origin, it doesn’t work. To make these things work, you need to use a localhost server.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading