单击下载按钮时如何显示文件保存文件对话框? [英] How to show file save file dialog box while click download button?

查看:172
本文介绍了单击下载按钮时如何显示文件保存文件对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示保存文件的对话框(选择要保存文件的路径),同时使用PrimeFaces单击下载按钮。我怎样才能实现这个目标?

I want to show dialog box to save the file (to select the path where you want to save the file) while clicking the download button using PrimeFaces. How can I achieve this?

推荐答案

PrimeFaces < p:fileDownload> 标签具有 contentDisposition 属性,您可以将其设置为内联(以显示内联文件)或附件(弹出另存为对话框)。

The PrimeFaces <p:fileDownload> tag has the contentDisposition attribute for that which you could set to inline (to display the file inline) or attachment (to pop a Save As dialogue).

<p:fileDownload ... contentDisposition="attachment" />

但是,它已默认为附件!您不应该明确指定它。

However, it defaults to attachment already! You shouldn't have the need to explicitly specify it.

因此,您的具体问题是由您的webbrowser本身引起的。大多数现代web浏览器可以配置为在检索到特定内容类型的文件时采取特定的默认操作。显然,您的配置始终无论内容配置如何都始终以内联方式显示。目前还不清楚你正在使用哪种网页浏览器,但是Firefox处理它的方式是最常见的并且让初学者感到困惑,因此我将针对它进行回答。

So your concrete problem is caused by your webbrowser itself. Most modern webbrowsers can be configured to take specific default actions when a file of a specific content type is been retrieved. Apparently yours is configured to always display it inline regardless of the content disposition. It's unclear which webbrowser you're using, but the way how Firefox handles it is the most commonly known and confusing among starters, so I'll target my answer on it.

当您在Firefox中下载PDF文件时,默认情况下会显示一个包含2个选项的对话框:在Adobe中打开它(内联)或将其保存到磁盘。在此之下,有一个复选框可以记住默认操作。

When you download for example a PDF file in Firefox, it'll by default show you a dialog with 2 options: open it (inline) in Adobe, or save it to disk. Below that, there's a checkbox to remember the default action.

显然你曾经勾选过该选项设置为内联打开文件,这样Firefox就再也不会问你是打开还是保存它。

Apparently you've ever ticked that while the option is set to open the file inline and this way Firefox will never ask you anymore whether to open or to save it.

您可以通过工具>选项>应用程序重新配置。

这篇关于单击下载按钮时如何显示文件保存文件对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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