www.webdeveloper.com
Results 1 to 4 of 4

Thread: Script to copy "strings" from text boxes on a webpage and save them in a csv file?

  1. #1
    Join Date
    Jun 2011
    Posts
    4

    Script to copy "strings" from text boxes on a webpage and save them in a csv file?

    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

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,257
    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.

  3. #3
    Join Date
    Jan 2011
    Posts
    117
    "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?!

  4. #4
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by blah2222 View Post
    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.
    Last edited by rnd me; 10-14-2012 at 01:19 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles