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