lightgallery.js
lightgallery.js copied to clipboard
Improve download btn functionality
Right now the download button only works for specific cases - Meta data (content-disposition) is related to an attachment, etc. .
Why not improving that functionality by just forcing the download based on the related image url, like:
fetch(url).then(res => res.blob()).then(file => {
let tmpUrl = URL.createObjectURL(file);
const aTag = document.createElement("a");
aTag.href = tmpUrl;
aTag.download = url.replace(/^.*[\\\/]/, '');
document.body.appendChild(aTag);
aTag.click();
URL.revokeObjectURL(tmpUrl);
aTag.remove();
}).catch(() => {
alert("Failed to download file!");
});
Something like that will always work, so also for an image url like this one:
See #226 - still an open task.
This issue has been automatically marked as stale because it has not had recent activity. If the issue is still valid for version 2.x, please re-open. Apologize for not responding on time. Thank you for your contributions.
Still an issue @andimg93