Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript从路径下载文件_Javascript_Html_Laravel_File_Download - Fatal编程技术网

javascript从路径下载文件

javascript从路径下载文件,javascript,html,laravel,file,download,Javascript,Html,Laravel,File,Download,下面是我用来下载文件的示例,但它只在下一个选项卡中打开文件。它不下载文件 function download(items) { items.forEach(function (item, index) { // console.log(item); var anchor = document.createElement('a'); anchor.href = item.url; anchor.target = '_blank'; anchor.dow

下面是我用来下载文件的示例,但它只在下一个选项卡中打开文件。它不下载文件

function download(items) {
 
  items.forEach(function (item, index) {
   // console.log(item);
    var anchor = document.createElement('a');
    anchor.href = item.url;
    anchor.target = '_blank';
    anchor.download = item.name;
    anchor.innerHTML ='download';
    setTimeout(function () {
    //  console.log(anchor);
      anchor.click();      
    }, index * 100);
  });
}
“下载”属性仅适用于相同来源的URL


此API调用获取URL并创建可下载的图像

您可以共享
item.URL
item.name
的外观吗?欢迎使用SO…生成了什么URL?你能不能把那个名字改成:“dummy.pdf”,网址是:“1/dummy.pdf”,我现在收到了“访问控制允许来源”错误
fetch("https://upload.wikimedia.org/wikipedia/commons/a/a3/June_odd-eyed-cat.jpg")
    .then(response => response.blob())
    .then(blob => {

        const blobURL = URL.createObjectURL(blob);
        const a = document.createElement("a");
        a.href = blobURL;
        a.innerHTML = "download"
        a.setAttribute('download', 'true')
        document.body.appendChild(a);

    })