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
JavaScript 'In' Operator for 'Undefined' Elements in Arrays
Node.Js Async/Await Using with MySQL
What's a Good Tool to Screen-Scrape with JavaScript Support
How to Update React Context from Inside a Child Component
Pagination on a List Using Ng-Repeat
JavaScript Custom Event Listener
Function to Calculate Distance Between Two Coordinates
Copy a Variable's Value into Another
How to Trigger a Bootstrap Modal Programmatically
How to Prevent Moment.Js from Loading Locales with Webpack
How to Split a String into an Array of Characters
Get All User Defined Window Properties
Converting JSON Results to a Date
Call JavaScript Function from Url/Address Bar
How to Load Image Files with Webpack File-Loader
How to Block Users from Closing a Window in JavaScript
Use Jquery to Scroll to the Bottom of a Div with Lots of Text