将页面另存为HTML对话框 [英] Save page as HTML dialog

查看:216
本文介绍了将页面另存为HTML对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以通过Javascript显示将页面另存为对话框?



我认为必须至少在Chrome / Chromium上是这样的浏览器功能。



如果不是,有什么选择?



当我说Save page as对话框时,我的意思是如何通过Javascript显示以下窗口(例如,当按下按钮时)。




解决方案

通过JavaScript Strictly, No。



但有两种选择, 1服务器端。

通过HTM5链接强制下载。


现在
HTML5
规格在
基本允许的超链接上定义了非常有用的下载属性在客户端强制下载行为,而不论服务器中Content-Type和Content-Disposition的内容为

Fiddled Here: http://jsfiddle.net/qmwxt/



< a href =网址下载>下载您的问题< / a>



在此阅读更多信息: https://stackoverflow.com/a/15970140/144665



在标题中设置Content-Disposition。



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



阅读更多:如何编码HTTP中的Content-Disposition头文件名参数?


Is possible to show the "Save page as" dialog via Javascript?

I think that there must be such a browser function, at least for Chrome/Chromium.

If not, what are the alternatives?

When I say "Save page as" dialog I mean how to make the following window appear via Javascript (when pressing a button, for example).

解决方案

Via JavaScript Strictly, No.

But here are two alternatives, 1 client side and 1 server side.

Force Download via HTM5 link.

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.

Fiddled Here: http://jsfiddle.net/qmwxt/

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

Read more here: https://stackoverflow.com/a/15970140/144665

Set Content-Disposition in the header.

Or if you have server side control set Content-Disposition in the header which forces the save dialog.

Read more here: How to encode the filename parameter of Content-Disposition header in HTTP?

这篇关于将页面另存为HTML对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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