JSFiddle - React, Tailwind, and code Playground

by Rational Rabbit

HTML

<script src="https://fastcdn.org/FileSaver.js/1.1.20151003/FileSaver.min.js"></script>
<a href="javascript:void(0)" onclick="SaveFile()">Click Here</a>

JavaScript

function SaveFile()
{
    var xhr = new XMLHttpRequest();
    
    var url = 'https://upload.wikimedia.org/wikipedia/commons/d/da/Internet2.jpg';
    
   	xhr.responseType = 'blob'; //Set the response type to blob so xhr.response returns a blob
    xhr.open('GET', url , true);
    
    xhr.onreadystatechange = function () {
        if (xhr.readyState == xhr.DONE) {
            //When request is done
            //xhr.response will be a Blob ready to save
            saveAs(xhr.response, 'image.jpeg');
        }
    };

    xhr.send(); //Request is sent
}