使用js从网站下载或仅保存图像文件

2024-04-07

我想使用 JavaScript 从网站下载或保存图像文件 纯粹的编码本身..因为我想下载近1000个jpeg,所以我想编写一个函数来调用和下载这些图像。

URL 可用,我想从中下载特定图像

请指导有关此事..


文件网址 = "http://www.b2hp.com/myProfilePic.jpg http://www.b2hp.com/myProfilePic.jpg";

var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function () {
  var a = document.createElement('a'); // create html element anchor
  a.href = window.URL.createObjectURL(xhr.response); // xhr.response is a blob
  a.download = "TEMP-1.jpg"; // Set the file name.
  a.style.display = 'none'; // set anchor as hidden
  document.body.appendChild(a);
  a.click();
  a.remove()
};
xhr.open('GET', fileUrl);
xhr.send();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用js从网站下载或仅保存图像文件 的相关文章

随机推荐