HTML5下载属性无法跨域工作?可以使它工作吗? [英] HTML5 download attribute not working cross-domain? Can it be made to work?

查看:48
本文介绍了HTML5下载属性无法跨域工作?可以使它工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下页面:

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

为什么第一个链接有效,而第二个链接却无效?我需要发送特定的标头,还是不能在子域上使用 download 属性?

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?

推荐答案

Chrome实际上确实允许跨域文件的下载属性,而没有CORS标头,但是Firefox引用了潜在的社交工程攻击,因此拒绝了.

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

检查此链接... HTML5从另一台服务器下载时,即使Access-Control-Allow-Origin设置为全部(*),下载属性也不起作用

您可以使用以下类似的php代理文件对其进行修复:

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);
?>

这篇关于HTML5下载属性无法跨域工作?可以使它工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆