HTML5 下载属性不能跨域工作?它可以工作吗?

标签 html download

<分区>

考虑以下页面:

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

为什么第一个链接有效,而第二个链接无效?我是否需要发送某个 header ,或者无法在子域上使用 download 属性?

最佳答案

Chrome 实际上确实允许跨源文件的下载属性,没有 CORS header ,但 Firefox 选择不允许,理由是潜在的社会工程攻击。

检查此链接... HTML5 download attribute not working when downloading from another server, even when Access-Control-Allow-Origin is set to all (*)

您可以使用 php 代理文件修复它,例如:

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

关于HTML5 下载属性不能跨域工作?它可以工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26921024/

相关文章:

javascript - textarea 焦点的问题

javascript - Flowplayer HTML5 全屏播放

javascript - jQuery 的奇怪问题

http - 在 Squeak 中,一旦 block 到达,就将大 HTTP 响应的 block 写入磁盘

javascript - 使用 Python 从网站下载 Javascript 文件

java - Android Activity 下载文件

asp.net-mvc-4 - System.OutOfMemoryException : Exception of type 'System.OutOfMemoryException' was thrown.在mvc 4中下载大文件

javascript - 获取 URL 的最后一段

android - 移动网站的图像尺寸是多少才能容纳 100% 的可用屏幕?

c# - 如何在 WinForm 应用程序中从 Web 下载文件