[英]Download files from array with url
I have an array with URLs from checked checkboxes, after this I need to download all checked files on click我有一个带有来自选中复选框的 URL 的数组,之后我需要在单击时下载所有选中的文件
array look like [url1,url2,url3]
数组看起来像
[url1,url2,url3]
my script works fine, collecting data from checkboxes and I can show it but I can't do anything to download this files我的脚本工作正常,从复选框收集数据,我可以显示它,但我不能做任何事情来下载这些文件
<script type="text/javascript">
function GetSelected() {
//Create an Array.
var selected = new Array();
//.
var tbl = document.getElementById("acf-group_62bea885d8d59");
//Reference all the CheckBoxes in Table.
var chks = tbl.getElementsByTagName("INPUT");
// Loop and push the checked CheckBox value in Array.
for (var i = 0; i < chks.length; i++) {
if (chks[i].checked) {
selected.push(chks[i].value);
}
}
//Display the selected CheckBox values.
if (selected.length > 0) {
alert("Selected values: " + selected.join(","));
}
};
</script>
I need to download selected file from ACF repeater field (file) in post.php For now I can only download only one file but I need to bulk download selected enter image description here我需要从 post.php 中的 ACF 转发器字段(文件)下载选定的文件现在我只能下载一个文件,但我需要批量下载选定的在此处输入图像描述
Solution to download files from a list of url :从 url 列表下载文件的解决方案:
const urls = ['url1', 'url2', 'url3'];
let fetchFile = function(url) {
return fetch(url).then(res => res.blob());
}
let exportFile = function(file) {
let a = document.createElement('a');
a.href = URL.createObjectURL(file);
a.setAttribute('download', '');
a.click();
}
for(const url of urls) {
fetchFile(url).then(file => exportFile(file));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.