将打开的网页保存为 HTML 文件
我有一个 HTML 页面。 当我点击一个按钮时,我想触发一个“保存 HTML 页面”之类的东西,以便我能够保存打开的网页。我还想知道使用 jquery / javascript 是否可以实现这一点。
I have an HTML page.
When I click a button, I'd like to trigger a Save HTML page kinda thing so that I'll be able to save the opened web page. I'd also like to know if this is possible using the jquery / javascript.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTML 页面无权访问文件系统。这将是一个安全问题。用户需要手动保存文件。
HTML pages do not have access to the filesystem. This would be a security issue. The user needs to save the file manually.
对于 IE,这很简单,因为 IE 实现了 document.execCommand:
MSDN 有一个明确的 示例。
如果您有兴趣让它在其他浏览器上工作,似乎没有任何客户端编程会调用“保存”对话框。
使用服务器端代码,您可以让按钮检索同一页面,并对随响应发送的 HTTP 标头进行以下更改:(
其中 filename.ext 显然是文件的名称)。
PHP 文档中 header() 函数的第一个 示例 展示了如何调用PDF 的下载对话框,Microsoft 还有另一个支持页面,其中包含 ASP 的示例。
With IE, it's simple as IE implements document.execCommand:
MSDN has an clear example of this.
If you're interested in having it work on other browsers, there doesn't seem to be any client-side programming that will invoke the Save dialogue box.
Using, server-side code, you can have the button retrieve the same page with the following change in the HTTP header sent with the response:
(where filename.ext is obviously the name of your file).
The first example in the PHP documentation for the header() function shows how to invoke the download dialog for a PDF, and Microsoft has another support page with an example for ASP.