0

I have a variable in javascript the contents of which are valid for a .csv file. I want the user to save its contents in a file of his/her choice. I do the following:

HTML

<button type="button" id="downloadCSV">Download CSV</button>

JS

$('#downloadCSV').click(function () {
    var csvContent = generateCSV(); //The function generates a valid CSV
    var encodedUri = encodeURI(csvContent);
    window.open(encodedUri);
});

This does two things that I don't want:

  1. Opens another chrome tab.
  2. just says 'download' in the windows pop up (Even the extension needs to be added manually). Instead of that I want it to have a default name with extension. Say foobar.csv

I have gone through similar questions like this but to no avail. How can I achieve this?

2
  • I am not sure, is it help to you, but check this: stackoverflow.com/questions/13405129/… Commented Nov 27, 2014 at 16:12
  • You can't do that with simple javascript. Commented Nov 27, 2014 at 16:32

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.