Does Execcommand Saveas Work in Firefox

Does execCommand SaveAs work in Firefox?

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>

Not able to execute document.execCommand in Edge

function ExportToCSV(gridContent, file_name) {
if (detectIE()) { // Checks IE and Edge
var _fileName = file_name + ".csv";
var blob = new Blob([decodeURIComponent(encodeURI(gridContent))], {
type: "text/csv;charset=utf-8;"
});
navigator.msSaveBlob(blob, _fileName);
} else {
..... for other browsers.........
}
}

execCommand not working

Update:

You may find this resource useful :)


Quoting:

Available only in the Win32 platforms
for IE, the execCommand( ) method
executes the named command.

Source: http://javascript.gakaa.com/document-execcommand-4-0-5-.aspx

More Specific Resource:

  • execCommand compatibility

Is there any way to 'simulate' right-click save-as command or force download of file in the browser with JavaScript?

Does your CDN allow you to specify the HTTP headers? Amazon cloudfront does, for example.

In Firefox, Write to a File using Javascript?

You can't do this, for hopefully obvious security reasons. JavaScript has no access to the file system...in IE it's not JavaScript, but ActiveX doing this...it just has a JavaScript API exposed.

The problem isn't that Firefox doesn't do this...it's that IE ever allowed it :)



Related Topics



Leave a reply



Submit