Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How do I change a filename on-download with javascript? Ask Question. Asked 10 years, 2 months ago. Active 4 years, 10 months ago. Viewed 21k times. Because changing a file name isn't possible in JavaSCript, this question is an exact duplicate of: stackoverflow.
Rob W, this question is not at all a duplicate of Q That is about a web application, this Q is about a client-side script. The OP has no control over the target page or server. Brock Adams What the OP asks is not possible at the client's side. Therefore, the question moves to "How to change the file name of the specific file", which has already been asked multiple times by other users.
Rob W, that doesn't make any sense. Anyway, this is possible client side, just not by using only Greasemonkey JS. Im pretty sure it's possible. Show 1 more comment. Active Oldest Votes. URL window. Micah Henning Micah Henning 1, 1 1 gold badge 16 16 silver badges 25 25 bronze badges. I can't make it work. In Chrome the file gets saved with the correct name, but it has a zero length. In Firefox, the length is correct, but the name is dsQ9lPaj.
Internet Explorer still does not supports the native ES6 promises, and Axios depends heavily on them. Download Algorithm Create a text area to enter the text data. This will help us to replace certain special characters with a combination of escape sequences. Append this created element to the body of the document HTML page. Use element.
Remove the element from the body of the document HTML page. Attach this link to the document and simulate a click using the. Remove this link from the document. If omitted, this value will default to the filename already given to the download file, and a location immediately inside the downloads directory. Each header is represented as a dictionary object containing the keys name and either value or binaryValue.
The headers that are forbidden by XMLHttpRequest and fetch cannot be specified, however, Firefox 70 and later enables the use of the Referer header.
Attempting to use a forbidden header throws an error. A boolean : if present and set to true, then associate this download with a private browsing session. This means that it will only appear in the download manager for any private windows that are currently open.
A boolean that specifies whether to provide a file chooser dialog to allow the user to select a filename true , or not false. If this option is omitted, the browser will show the file chooser or not based on the general user preference for this behavior in Firefox this preference is labeled "Always ask you where to save files" in about:preferences, or browser.
Note: Firefox for Android raises an error if saveAs is set to true. The parameter is ignored when saveAs is false or not included. A Promise. If the download started successfully, the promise will be fulfilled with the id of the new downloads.
0コメント