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 6 of 6
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Save As Dialog without new Window (AJAX)

    Hey guys, I've been experimenting around with a way to get a "Save As" dialog to pop up prompting the user to download a certain file from the server.
    How I've done this so far is open a window in Javascript to a PHP file, server side, passing an argument through _GET. The PHP generates the file and then sends a header request to download. Simple enough. The problem is that using this method opens a blank window in addition to the Save As Dialog. Is there anyway to fool the browser/ hide the window/ etc, so two windows don't pop up at the same time everytime my users press the download button?
    I am also pretty familiar with AJAX techniques, so if anyone has a solution along that route as well I'd appreciate it.


    Cheers,
    Q

  • #2
    VR2
    VR2 is offline
    New Coder
    Join Date
    Jul 2006
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There maybe a better way but you could target a hidden frame or IFrame. so your link could be:

    <a href="script.php" target="hiddenIframe">Click here</a>
    <iframe src="javascript:false" name="hiddenIframe" style="display:none"></iframe>

    this will stop the second window appearing.

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HTTP header = Content-disposition: attachment

    I don't use PHP, so I'm not sure how you would do this with PHP.

    I have a PERL/CGI script that I use (download.pl) to allow users to download files (and to keep them from downloading more than two files at a time)

    In PERL, I just change the content-disposition in the HTTP header to be:

    Content-disposition: attachment

    When the user clicks a link that returns a content-dispostition of attachment the page doesn't change and a download dialog opens.
    Last edited by VortexCortex; 11-05-2006 at 05:34 AM. Reason: Now standards compliant.

  • #4
    New Coder
    Join Date
    Sep 2006
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nice got it to work with the hidden iframe. great solution.


    Q

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,607
    Thanks
    0
    Thanked 645 Times in 635 Posts
    You can change the header in PHP just as easily as in PERL.

    header('Content-Disposition: attachment');

    A simple HTML link to the PHP will then offer it for download.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello quakerstate79

    I working on similar requirement. I have a zip file in the server at one particular location. can you help me with some code snippet

    like how to trigger a PHP to access the zip file( server) and then sends a header request to download the zip file.

    I am not Java Script or PHP guru. any help is greatly appreciated.


  •  

    Posting Permissions

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