Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts

    jQuery dynamic file download

    Hi folks!

    What I need:

    Dynamically generate a text file and submit it for download. The data is generated on client side.

    What I don't know:

    1. Do I have to use PHP here to generate the file since I have all the data in the client code?
    2. If yes, what method would you suggest? iframe? jQuery plugin? anything I can't think of?

    Thanks in advance!
    Chuck Norris counted to infinity.
    Twice.

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts
    Nobody on this?

    TIA
    Chuck Norris counted to infinity.
    Twice.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,400
    Thanks
    11
    Thanked 595 Times in 575 Posts
    target='ing a hidden iframe, POST to php to echo the data while adding a content-dispostion header to specify type and filename.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #4
    Regular Coder
    Join Date
    Jan 2008
    Location
    Geneva, Switzerland
    Posts
    413
    Thanks
    12
    Thanked 29 Times in 29 Posts
    Right. Thanks.

    So there's no way to generate a file without the use of a server side language?
    Chuck Norris counted to infinity.
    Twice.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,400
    Thanks
    11
    Thanked 595 Times in 575 Posts
    you can use js, but it's a bit rough in that you can't specify a filename, so the data will have a random filename:

    Code:
    function downloadText(strText){
     return window.open("data:text/rtf,"+escape(strText));
    }
    
    downloadText("Hello World!");
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    LinkBacks (?)


    Posting Permissions

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