admin管理员组

文章数量:1022679

I am using the FileSaver.js to download file using the code below. This file is automatically downloaded to a default folder (Tested in Chrome), but I need to show a window dialog that says something like "Save as file...". Thanks!

var blob = new Blob([data], {type: "application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet"});
saveAs(blob, "file.xlsx");

I am using the FileSaver.js to download file using the code below. This file is automatically downloaded to a default folder (Tested in Chrome), but I need to show a window dialog that says something like "Save as file...". Thanks!

var blob = new Blob([data], {type: "application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet"});
saveAs(blob, "file.xlsx");
Share Improve this question edited Jul 28, 2018 at 20:15 juzraai 5,9538 gold badges34 silver badges48 bronze badges asked Jul 28, 2018 at 20:09 Naive DeveloperNaive Developer 7101 gold badge9 silver badges17 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

This dialog you are talking about is browser settings specific. Meaning in Google Chrome for example in Settings/Advanced/Downloads section you have a setting:

Ask where to save each file before downloading which you can set true/false.

If you disable this setting it would always ask you and bring the SaveAs dialog.

Hope this helps.

I need to show a window dialog that says something like "Save as file...". Thanks!

To solve your problem as a whole I remend using a prompt method which will prompt the user with a dialog to save the file name.

In addition, there are many libraries out there for custom dialogs as well like AlertifyJS or SweetAlert2 which I used in my Flat Design Character Maker.

Here's a simple example of the prompt method.

saveFile.onclick = function() {
  var filename = prompt("Define your file name.");
  if (filename) {
    alert("File saved!");
  } else {
    alert("Save canceled!");
  }
}
<button id="saveFile">Save file</button>

As of now, according to this github discussion, it is not possible.

I am using the FileSaver.js to download file using the code below. This file is automatically downloaded to a default folder (Tested in Chrome), but I need to show a window dialog that says something like "Save as file...". Thanks!

var blob = new Blob([data], {type: "application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet"});
saveAs(blob, "file.xlsx");

I am using the FileSaver.js to download file using the code below. This file is automatically downloaded to a default folder (Tested in Chrome), but I need to show a window dialog that says something like "Save as file...". Thanks!

var blob = new Blob([data], {type: "application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet"});
saveAs(blob, "file.xlsx");
Share Improve this question edited Jul 28, 2018 at 20:15 juzraai 5,9538 gold badges34 silver badges48 bronze badges asked Jul 28, 2018 at 20:09 Naive DeveloperNaive Developer 7101 gold badge9 silver badges17 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

This dialog you are talking about is browser settings specific. Meaning in Google Chrome for example in Settings/Advanced/Downloads section you have a setting:

Ask where to save each file before downloading which you can set true/false.

If you disable this setting it would always ask you and bring the SaveAs dialog.

Hope this helps.

I need to show a window dialog that says something like "Save as file...". Thanks!

To solve your problem as a whole I remend using a prompt method which will prompt the user with a dialog to save the file name.

In addition, there are many libraries out there for custom dialogs as well like AlertifyJS or SweetAlert2 which I used in my Flat Design Character Maker.

Here's a simple example of the prompt method.

saveFile.onclick = function() {
  var filename = prompt("Define your file name.");
  if (filename) {
    alert("File saved!");
  } else {
    alert("Save canceled!");
  }
}
<button id="saveFile">Save file</button>

As of now, according to this github discussion, it is not possible.

本文标签: javascriptFileSaverjs with a dialogStack Overflow