问题描述
为什么在ff / chrome中不行? javascript:document.execCommand('SaveAs','true' ,的 'http://www.google.com');
(用作书签)
execCommand在浏览器中并没有完全标准化。事实上,execCommand('SaveAs',...)似乎只支持IE。强制保存的推荐方法是使用content-disposition:attachment标头,如
因为这是HTTP头的一部分,所以可以使用它任何文件类型。如果您使用的是Apache,您可以使用.htaccess文件添加标题,如。例如:
< FilesMatch\.pdf $>
< IfModule mod_headers.c>
Header set Content-Dispositionattachment
#用于旧浏览器
头文件集内容类型application / octet-stream
< / FilesMatch>
Why does this not work in ff/chrome?
javascript: document.execCommand('SaveAs','true','http://www.google.com');
(used as a bookmarklet)
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
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中工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!