execCommand SaveAs 在 Firefox 中工作吗? [英] Does execCommand SaveAs work in Firefox?

查看:29
本文介绍了execCommand SaveAs 在 Firefox 中工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这在 ff/chrome 中不起作用?

Why does this not work in ff/chrome?

javascript: document.execCommand('SaveAs','true','http://www.google.com');

(用作书签)

推荐答案

execCommand 在浏览器中并未完全标准化.事实上, execCommand('SaveAs', ...) 似乎只在 IE 上受支持.强制另存为的推荐方法是使用 content-disposition: 附件标头,如 http://www.jtricks.com/bits/content_disposition.html

execCommand is not completely standardized across browsers. Indeed, execCommand('SaveAs', ...) only seems to be supported on IE. The recommended way to force a save-as would be to use a content-disposition: attachment header, as described in http://www.jtricks.com/bits/content_disposition.html

由于这是 HTTP 标头的一部分,您可以在任何文件类型上使用它.如果您使用的是 apache,则可以使用 .htaccess 文件添加标头,如 此处.例如:

Since this is part of the HTTP header, you can use it on any file type. If you're using apache, you can add headers using the .htaccess file, as described here. For example:

<FilesMatch ".pdf$">
<IfModule mod_headers.c>
Header set Content-Disposition "attachment"
# for older browsers
Header set Content-Type "application/octet-stream"
</IfModule>
</FilesMatch>

这篇关于execCommand SaveAs 在 Firefox 中工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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