Why does this not work in ff/chrome?
javascript: document.execCommand('SaveAs','true','http://www.google.com');
(used as a bookmarklet)
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:
Firefox doesn't support execCommand. In fact it seems to be IE-only.
It is possible to do this in Firefox via data URIs (see also Download data url file ) and optionally via the download attribute.
See http://html5-demos.appspot.com/static/a.download.html for an HTML5 shim demo.
How to force save as dialog box in firefox besides changing headers? also covers this topic.
You can also test it by the following Firefox-tested demo.
The following also works for URLs as well as JavaScript-initiated loads without the download attribute (though this approach does not allow a file name, it does allow a preview in a new tab):
As Microsoft puts it, "There is no public standard that applies to this method."