Download Test

HTML

<!DOCTYPE html>
<div>


<form
id="test">

OS:<input type="text" id="myInput" placeholder="'OSX' or 'Windows'">

</form>

<p>
<input id="demo" type='button' name='Next' value='Search'
onclick= myFunction(myInput) />
</p>
<button>Export table to CSV</button>
</div>
<div id="frame">

</div>

JavaScript

function myFunction(myInput) {
  var userInput = document.getElementById("myInput").value;
 
   var Input = document.getElementById("demo").innerHTML = userInput;
   

if (userInput){
  
  var startUrl = "https://fusiontables.google.com/embedviz?viz=GVIZ&amp;t=TABLE&amp;q=select+col0%2C+col1%2C+col2%2C+col3+from+1XIDlbUpAJLcUtDf-cYoOZzpLi2KSN0ZH93sHJxVq+where+col3+%3D+'";

 
  var endUrl = "'&amp;containerId=googft-gviz-canvas";
	var URL = startUrl+Input+endUrl;
 document.getElementById("frame").innerHTML = '<iframe src="' + URL +
    '" width="1000" height="720" scrolling="yes" border="0" sandbox="allow-same-origin allow-scripts"></iframe>';
    }

}

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

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

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

    // File name
    downloadLink.download = filename;

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

    // Make sure that the link is not displayed
    downloadLink.style.display = "none";

    // Add the link to your DOM
    document.body.appendChild(downloadLink);

    // Lanzamos
    downloadLink.click();
}

function export_table_to_csv(html, filename) {
	var csv = [];
	var iframe = document.getElementById('googft-gviz-canvas').contentWindow.document.body.innerHTML;
  alert(iframe);
  var rows = document.querySelectorAll("table tr");
 

	
    for (var i = 0; i < rows.length; i++) {
		var row = [], cols = rows[i].querySelectorAll("td, th");
		
        for (var j = 0; j < cols.length; j++) 
            row.push(cols[j].innerText);
        
		csv.push(row.join(","));		
	}

    // Download CSV
    download_csv(csv.join("\n"), filename);
}

document.querySelector("button").addEventListener("click", function () {
    var html = document.querySelector("table").outerHTML;
	export_table_to_csv(html, "table.csv");
});