+ Reply to Thread
Results 1 to 6 of 6

Thread: Creating "Save as..." Popup in Javascript

  1. #1
    Goran is offline New Born Goran is on a distinguished road
    Join Date
    Jan 2007
    Posts
    2
    Rep Power
    0

    Creating "Save as..." Popup in Javascript

    i have a question, okey maybe it's not directly relevant with PHP.
    i have a webpage that contains .doc and .txt files, of course when you click any icon with left mouse click then windows opening the .doc or .txt files.
    can i propmt the user with "save target as" dialog box when he/she left click to icons with java script? i dont want to tell them that hey, please right click and save (and i dont wanna zip the files).
    How can i do this? it is possible with java (xor with PHP help)?

  2. #2
    Calamitie's Avatar
    Calamitie is offline Banned Calamitie will become famous soon enough
    Join Date
    Feb 2005
    Location
    Moodles, UK
    Posts
    2,258
    Rep Power
    0

    Re: Creating "Save as..." Popup in Javascript

    I am almost certain you can't do this what-so-ever, but you can send a header (in PHP) that forces the browser to prompt for download.

    I can't remember the actual header - it's something like "Content-type: application/[something]".

    Hope that helps a little...

  3. #3
    Goran is offline New Born Goran is on a distinguished road
    Join Date
    Jan 2007
    Posts
    2
    Rep Power
    0

    Re: Creating "Save as..." Popup in Javascript

    Thank , I hope someone will add smth too)))

  4. #4
    Calamitie's Avatar
    Calamitie is offline Banned Calamitie will become famous soon enough
    Join Date
    Feb 2005
    Location
    Moodles, UK
    Posts
    2,258
    Rep Power
    0

    Re: Creating "Save as..." Popup in Javascript

    Welcome to YoungCoders by the way!

    Feel free to introduce yourself here: http://www.youngcoders.com/forum27.html

  5. #5
    <? Ashley ?> is offline a.k.a. fLUx <? Ashley ?> is on a distinguished road
    Join Date
    Oct 2006
    Location
    United Kingdom
    Age
    21
    Posts
    297
    Rep Power
    7

    Re: Creating "Save as..." Popup in Javascript

    This may do it:
    PHP Code:
    <?php
    header
    ("Content-disposition: attachment;
    filename=name-of-file"
    );
    ?>

  6. #6
    Join Date
    Dec 2006
    Location
    University of York, UK
    Age
    23
    Posts
    1,837
    Rep Power
    8

    Re: Creating "Save as..." Popup in Javascript

    I was just stumbling around the PHP manual looking for something completely unrelated and came across this:


    If you want the user to be prompted to save the data you are sending, such as a generated PDF file, you can use the Content-Disposition header to supply a recommended filename and force the browser to display the save dialog.

    <?php
    // We'll be outputting a PDF
    header('Content-type: application/pdf');

    // It will be called downloaded.pdf
    header('Content-Disposition: attachment; filename="downloaded.pdf"');

    // The PDF source is in original.pdf
    readfile('original.pdf');
    ?>
    Note: There is a bug in Microsoft Internet Explorer 4.01 that prevents this from working. There is no workaround. There is also a bug in Microsoft Internet Explorer 5.5 that interferes with this, which can be resolved by upgrading to Service Pack 2 or later.
    Seems to be what Ashley suggested! Only giving the content-type as well.

    Mike

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Javascript Popup Window
    By exiledfate in forum JavaScript Coding
    Replies: 10
    Last Post: 06-06-2005, 03:42 PM
  2. Javascript
    By YoungCoder in forum JavaScript Coding
    Replies: 5
    Last Post: 09-25-2004, 04:16 AM
  3. How to Start Javascript
    By Vio-Bear in forum Javascript Articles
    Replies: 0
    Last Post: 09-05-2004, 09:14 AM
  4. javascript part 2
    By hayabusa in forum Javascript Articles
    Replies: 0
    Last Post: 09-05-2004, 09:02 AM
  5. Javascript part 1
    By hayabusa in forum Javascript Articles
    Replies: 0
    Last Post: 09-05-2004, 09:01 AM

Posting Permissions

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