Convert HTML table tags to CSV using javascript

Recently, I was working in an old Coldfusion environment and I wanted to export a data from a database to CSV.

Instead of writing CSV parsing in Coldfusion I used this Javascript code.

function downloadCSV(csv, filename) {
    var csvFile;
    var downloadLink;

    // CSV file
    csvFile = new Blob([csv], {type: "text/csv"});

    // Download link
    downloadLink = document.createElement("a");

    // File name = filename;

    // Create a link to the file
    downloadLink.href = window.URL.createObjectURL(csvFile);

    // Hide download link = "none";

    // Add the link to DOM

    // Click download link;

HTML Code and Calling the above function
I displayed the data from table in a web page and called this function
I set text color as white.
 }, 1000);

I agree. this is an indirect approach but this will be useful when your data is less than 1 MB and when working with old programming language or frameworks like Coldfusion, Adobe, COBOL 🙂