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
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 collect the information and format it to your hearts' desire, but you cannot save a file using JS only.
You need a server side language to accomplish this task.
"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?"
and than post them as mail attachments to your account? or what?!
you can download text from javascript. i'll let you connect the textboxes, but here is my magic:
tested in ch+ffCode: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");
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.