AngularJS:显示操作系统"文件保存"对话但不实际保存

时间:2016-12-12 18:21:31

标签: javascript angularjs

所有我需要做的事情,在ng-click打开文件"保存"来自浏览器的对话框,跨平台。我并不是想拯救任何东西;这只是一个演示/原型,我想展示给利益相关者的流程。

我在SO上找到的每个答案都是保存窗口内容或文件blob的复杂方法,但我不需要这样做。

我希望类似于$ window.prompt,但对于文件对话框。

有什么事吗?

2 个答案:

答案 0 :(得分:1)

建立关闭azad的评论,您可以使用隐藏的<input type="file">并使用<label>触发它。

修改:将<label>设置为样式,以便更好地与浏览器兼容。

#download {
  display: none;
}
.download-button {
  border-radius: 28px;
  font-family: Arial;
  color: white;
  font-size: 14px;
  background: #3498db;
  padding: 10px 15px 10px 15px;
  display: inline-block;
}
.download-button:hover {
  background: #3cb0fd;
}
<input id="download" type="file" />
<label for="download" class="download-button">
  Save As
</label>

答案 1 :(得分:0)

您可以使用带有下载属性的锚标记。

<a href="#" download="defaultfilename">Click me</a>