HTML5 download attribute not working cross-domain? Can it be made to work? [duplicate]

狂风中的少年 提交于 2020-12-06 07:04:22

问题


Consider the following page:

https://8chan.co/stackoverflow.html

Why does the first link work, but the second link doesn't? Do I need to send a certain header, or is it impossible to use the download attribute on a subdomain?


回答1:


Chrome actually does allow the download attribute on cross-origin files, without CORS headers, but Firefox chose not to, citing potential social-engineering attacks.

Check this link... HTML5 download attribute not working when downloading from another server, even when Access-Control-Allow-Origin is set to all (*)

You could fix it with php proxy file something like:

<?php
$url = $_GET['file'];
$name = $_GET['name'];
header("Content-type: application/$ext");
header("Content-Disposition: attachment; filename=".$name);
echo readfile($url);
?>


来源:https://stackoverflow.com/questions/26921024/html5-download-attribute-not-working-cross-domain-can-it-be-made-to-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!