相关疑难解决方法(0)

如何使用Content-disposition强制文件下载到硬盘?

我想强制浏览器下载pdf文件.

我使用以下代码:

<a href="../doc/quot.pdf" target=_blank>Click here to Download quotation</a>
Run Code Online (Sandbox Code Playgroud)

它使浏览器在新窗口中打开pdf,但我希望它在用户单击时下载到硬盘驱动器.

我发现它Content-disposition用于此,但我如何在我的情况下使用它?

html download httpresponse content-disposition

69
推荐指数
2
解决办法
11万
查看次数

将Content-Disposition标头设置为仅在特定目录中的文件上附件?

我在我的htaccess文件中有这条规则强制链接文件下载而不是在浏览器中打开:

<FilesMatch "\.(gif|jpe?g|png)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)

有没有办法改变它RegExp所以它只适用于某个目录中的文件?

谢谢

apache .htaccess header

16
推荐指数
2
解决办法
2万
查看次数

从交叉文档消息传递中加载从event.data获取的pdf

对于知道答案的人来说,简单点.我的代码通过跨文档消息传递成功地从网站下载pdf.但是,我现在想在浏览器中显示pdf,可能在iframe或数据对象中.可能我需要知道pdf存储为已下载的本地URL.请帮忙,可能很容易点.请参阅此处的小提琴以获取我的代码.

重要提示:因为我想下载文件,我不想简单地制作client.src ="http://ops.epo.org/3.0/rest-services/published-data/images/US/7123345/B2/thumbnail .PDF?范围= 1"

HTML代码:

    <input type="button" onclick="runit()" value="runit"></input>
    <iframe width=100 height=100 id="client" src="http://ops.epo.org/3.0/xss/crosssitescript.html" />
Run Code Online (Sandbox Code Playgroud)

Javascript代码:

function runit() {
    // Get the iframe window object
    var client = document.getElementById('client');
    // Create the data string to be passed to the OPS JavaScript
    var data = "{'url' : 'http://ops.epo.org/3.0/rest-services/published-data/images/US/7123345/B2/thumbnail.pdf?Range=1', " + "'method' : 'GET', " + "'requestHeaders' : {'Accept': 'application/pdf' } " + "}";
    // Use the postMessage() method in order to send the data to the
    // iframe …
Run Code Online (Sandbox Code Playgroud)

javascript pdf messaging cross-domain

4
推荐指数
1
解决办法
1463
查看次数