
Originally Posted by
blah2222
Hi,
Say there are two text boxes on a web page. Is there a way to add a button to your browser to save those specific strings to a predetermined csv file?
Random question, but I'm an absolute noob and don't know if this is feasible.
Cheers,
J
you can download text from javascript. i'll let you connect the textboxes, but here is my magic:
Code:
function download(strData,strFileName,strMimeType){var D=document,A=arguments,a=D.createElement("a"),d=A[0],n=A[1],t=A[2]||"text/plain";a.href="data:"+strMimeType+","+escape(strData);if('download'in a){a.setAttribute("download",n);a.innerHTML="downloading...";D.body.appendChild(a);setTimeout(function(){var e=D.createEvent("MouseEvents");e.initMouseEvent("click",true,false,window,0,0,0,0,0,false,false,false,false,0,null);a.dispatchEvent(e);D.body.removeChild(a);},66);return true;};var f=D.createElement("iframe");D.body.appendChild(f);f.src="data:"+(A[2]?A[2]:"application/octet-stream")+(window.btoa?";base64":"")+","+(window.btoa?window.btoa:escape)(strData);setTimeout(function(){D.body.removeChild(f);},333);return true;}
download("a,b,c\n1,2,3", "demo1.csv", "text/csv");
tested in ch+ff
a little known fact is that a simple html page saved as page.xls will open just fine in excel.
for IE users, you set doucment.body.innerHTML to a table, and trigger the "saveas" document.execCommand using IE-only syntax.
Bookmarks