I published, in full, your code on my server and really instead of downloading the file, is opening.
<!DOCTYPE html>
<html>
<body>
<a href="https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/HTML5_logo_and_wordmark.svg/1200px-HTML5_logo_and_wordmark.svg.png" download> download</a>
</body>
<!DOCTYPE html>
<html>
<body>
<a href="1200px-HTML5_logo_and_wordmark.png" download> download</a>
</body>
CONCLUSION
For logical and even security reasons, the download is decided by the website developer. I can download any file as long as it is published on my domain. Otherwise anyone could download any file from the network.
With Jquery (para imagens)
it is possible to open the download window directly
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script language="javascript">
var image = new Image();
image.crossOrigin = "anonymous";
image.src = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/HTML5_logo_and_wordmark.svg/1200px-HTML5_logo_and_wordmark.svg.png";
// get file name - you might need to modify this if your image url doesn't contain a file extension otherwise you can set the file name manually
var fileName = image.src.split(/(\\|\/)/g).pop();
image.onload = function () {
var canvas = document.createElement('canvas');
canvas.width = this.naturalWidth; // or 'width' if you want a special/scaled size
canvas.height = this.naturalHeight; // or 'height' if you want a special/scaled size
canvas.getContext('2d').drawImage(this, 0, 0);
var blob;
// ... get as Data URI
if (image.src.indexOf(".jpg") > -1) {
blob = canvas.toDataURL("image/jpeg");
} else if (image.src.indexOf(".png") > -1) {
blob = canvas.toDataURL("image/png");
} else if (image.src.indexOf(".gif") > -1) {
blob = canvas.toDataURL("image/gif");
} else {
blob = canvas.toDataURL("image/png");
}
$("body").html("<br><a download='" + fileName + "' href='" + blob + "'>download</a>");
};
</script>
Bibliography canvas
Have you tried it with any kind of file other than image? I believe that in this case there is some browser configuration to open the image instead of downloading it.
– Woss
Already, this "download" tag only works on Edge :(
– Flavio
The download attribute works on other browsers, I believe that all, at least the main ones, Chrome, firefox, operates, ...
– Costamilam