Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
122
rated 0 times [  123] [ 1]  / answers: 1 / hits: 70706  / 15 Years ago, thu, may 7, 2009, 12:00:00

Why does this not work in ff/chrome?



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


(used as a bookmarklet)


More From » firefox

 Answers
20

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>

[#99581] Saturday, May 2, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
magdalena

Total Points: 364
Total Questions: 101
Total Answers: 92

Location: Namibia
Member since Mon, Nov 14, 2022
2 Years ago
;