javascript - 将页面另存为 HTML 对话框

标签 javascript html google-chrome

<分区>

是否可以通过 Javascript 显示 “页面另存为” 对话框?

我认为必须有这样的浏览器功能,至少对于 Chrome/Chromium。

如果不能,有什么替代方案?

当我说“将页面另存为”对话框时,我的意思是如何通过 Javascript 显示以下窗口(例如,当按下按钮时)。

最佳答案

严格通过 JavaScript,否。

但这里有两种选择,一种是客户端,一种是服务器端。

通过 HTM5 链接强制下载。

Now the HTML5 spec defines a very useful download attribute on hyperlinks that basically allows to force download behavior on client-side, regardless of what comes in Content-Type and Content-Disposition from the server.

在这里摆弄:http://jsfiddle.net/qmwxt/

<a href="URL" download> Download your Question</a>

在这里阅读更多:https://stackoverflow.com/a/15970140/144665

在 header 中设置 Content-Disposition。

或者,如果您有服务器端控件,请在 header 中设置 Content-Disposition 以强制保存对话框。

在这里阅读更多:How to encode the filename parameter of Content-Disposition header in HTTP?

关于javascript - 将页面另存为 HTML 对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19501929/

相关文章:

css - 使用 FF3.5 与 FF3.0 的 td 内部跨度的不同 css 渲染

google-chrome - 使用 Google Analytics 跟踪嵌入的 YouTube 视频

google-chrome - "Identifier [...] has already been declared(…)"。如何在 Chrome Devtools 控制台中取消设置类变量?

google-chrome - Chrome 扩展程序中的接收错误 : Unchecked runtime. lastError : Could not establish connection. 接收端不存在

javascript - Chrome 打包应用程序 - 查看是否在 kiosk 模式下运行

javascript - 使用 jquery.when 和 done 将值从一个 ajax 调用传递到另一个

CSS:全尺寸 div 显示浏览器滚动条

javascript - 向子菜单下拉列表添加延迟 - bootstrap3

javascript - 通过 AJAX 调用问题 knockout 自定义验证

jquery - 图像未显示在 Internet Explorer 中