I am trying to download something from another website, I have tried this but didn't work. Please I need a help here
<a href="https://www.samanthaming.com/logo.png" class="text-1 text-uppercase" download> download here</a>
I am trying to download something from another website, I have tried this but didn't work. Please I need a help here
<a href="https://www.samanthaming.com/logo.png" class="text-1 text-uppercase" download> download here</a>
At first, make sure the download link is valid. Now You can make a custom javascript function to force download from an external link.
<script>
function downloadForce(link){
var url = link.getAttribute("data-href");
var fileName = link.getAttribute("download");
link.innerText = "Downloading...";
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "blob";
xhr.onload = function(){
var urlCreator = window.URL || window.webkitURL;
var imageUrl = urlCreator.createObjectURL(this.response);
var tag = document.createElement('a');
tag.href = imageUrl;
tag.download = fileName;
document.body.appendChild(tag);
tag.click();
document.body.removeChild(tag);
link.innerText="download here";
}
xhr.send();
}
</script>
<a class="text-1 text-uppercase" href="#" data-href='https://i.imgur.com/U2KQsBD.jpeg' download="image.jpeg" onclick='downloadForce(this)'>download here</a>