Resource interpreted as Document but transferred with MIME type application/zip

后端 未结 18 2372
不思量自难忘°
不思量自难忘° 2020-11-27 10:54

With Chrome 12.0.742.112, if I redirect with the following headers:

HTTP/1.1 302 Found 
Location: http://0.0.0.0:3000/files/download.zip
Content-Type: text/h         


        
18条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 11:18

    I had a similar issue when performing a file download through Javascript. Adding the download attribute made no difference but adding target='_blank' did - I no longer get the 'Resource interpreted as Document...' console message.

    Here's my nicely simple code:

    var link = document.createElement('a');
    link.target = '_blank';
    link.href = url;
    document.body.appendChild(link); // Required for Firefox
    link.click();
    link.remove(); 
    

    I haven't tried it with direct HTML but would expect it to work.

    Note I discovered that Firefox requires the link to be appended to the document whereas Chrome will work without it.

提交回复
热议问题