Oumaya
Oumaya

Reputation: 655

IS it possible to specify where to download a file in hyperlink

I am trying to download a file via an hyperlink after converting a html table to csv, here is my code:

function exportTableToCSV($table, filename) {

    var $rows = $table.find('tr'),
       ...
        csv = '"' + $rows.map(function (i, row) {
           ...

        // Data URI
        csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);

    $(this)
        .attr({
        'download': filename,
        'href': csvData,
        'target': '_blank'
    });
}

It works fine , onclick the hyperlink a "save as" pop up window is opened to save the file and download it.I don't want to pop up the "save as" but automatically download the file to the default download location set in the browser.

Is there any idea to get the download location and set it appropriately. Any help will be appreciated.

Upvotes: 0

Views: 62

Answers (2)

bitifet
bitifet

Reputation: 3659

No. For security reason, browsers doesn't allow to write anything in client side filesystem without user interaction.

Otherwise you could overwrite its files from server side.

Upvotes: 1

Bluety
Bluety

Reputation: 1909

You can link your file and add download attribute like so:

<a href="file.csv" download="namefile.csv">file CSV (2Kb)</a>

[edit] I'm not sure to answer the question ...

Upvotes: 0

Related Questions