Note: This method may fail for cross-origin URLs because modern browsers ignore the download attribute for security reasons when the URL is on a different domain. 3. The Robust Approach: Fetch API and Blobs
How to Download Image on Button Click in JavaScript? - GeeksforGeeks
For images hosted on the same origin (the same domain), the most efficient method is using the download attribute in an anchor tag. This attribute instructs the browser to download the linked resource instead of navigating to it.
The value of the download attribute becomes the default filename for the saved file. 2. The Dynamic Approach: Programmatic Button Click