Simple file link or button doesnt work - Javascript

This is a discussion on Simple file link or button doesnt work - Javascript ; guys, in my web app, i have a simple download button and a href which points to a file on my server, when the user clicks on the button or the link, the file should simply be downloaded to the ...

+ Reply to Thread
Results 1 to 4 of 4

Simple file link or button doesnt work

  1. Default Simple file link or button doesnt work

    guys,

    in my web app, i have a simple download button and a href which points
    to a file on my server, when the user clicks on the button or the
    link, the file should simply be downloaded to the users machine. now
    this file is a postgres backup file with the .backup extension.

    now when i use the button, in FF the file download button pops up and
    i can save the file, i can also right click the href and go save link
    as. and it works fine.

    but when i use the button or link in IE, it simply opens up the file
    in IE as text and displays a bunch a garbage. now the user needs to be
    able to download the file and not view it. also on the href link, when
    the right clicks and goes save target as IE automatically adds
    the .html extension to the file. now i dont have the .backup extension
    in my registered file types.

    just to end, my href is, <a href="http://localhost:8080/Backup/
    Today.backup">Download</a> and the button is,
    <input type="button" value="Download" onclick="location.href('http://
    localhost:8080/Backup/Today.backup')">

    please help me. all i want the user to be able to do is, to download
    the file, and they can either go right click and save target or just
    click on it and the download dialog should pop up. thanks.


  2. Default Re: Simple file link or button doesnt work

    pd said:

    >please help me. all i want the user to be able to do is, to download
    >the file, and they can either go right click and save target or just
    >click on it and the download dialog should pop up. thanks.


    That's not the way browsers are supposed to work. The browser
    should display the file that you click on in the window if it
    knows how. Only if it doesn't know how (or knows that it isn't
    safe to try), should it offer to download the contents. Unless,
    of course, the server tells the browser that the file should
    take some other action.


    --


  3. Default Re: Simple file link or button doesnt work

    Lee said the following on 5/31/2007 10:04 PM:
    > pd said:
    >
    >> please help me. all i want the user to be able to do is, to download
    >> the file, and they can either go right click and save target or just
    >> click on it and the download dialog should pop up. thanks.

    >
    > That's not the way browsers are supposed to work. The browser
    > should display the file that you click on in the window if it
    > knows how. Only if it doesn't know how (or knows that it isn't
    > safe to try), should it offer to download the contents. Unless,
    > of course, the server tells the browser that the file should
    > take some other action.


    Or, the user has explicitly told the browser how to handle a particular
    file. IE and FF both have that setting available to the user.

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

  4. Default Re: Simple file link or button doesnt work

    It's true that browsers have various sets of "default behaviors" for
    various mimetypes:

    - some known mimetypes will by default be displayed inside the
    browser.
    - some known mimetypes will by default be downloaded to the desktop.
    - when no mime type is sent, and the browser doesn't recognize the
    file type, then anything could happen, and i suspect that's what's
    happening with your backup file.

    You can override the download vs show-in-browser "default behavior",
    thru the "content-disposition" http header field:

    http://www.ietf.org/rfc/rfc2183.txt

    Try configuring your http server so that .backup files will have a
    correct mime type if one is defined, but more relevantly, try to make
    sure your server sends an additional HTTP Header:

    Content-Disposition: attachment; filename=MYFILE.backup

    Flickr.com has some good examples of overriding a browser's default
    behavior of loading images inside the browser window and forcing a
    download thru the Content-Disposition header. If you have a flickr
    account, look at a picture's "all sizes" page, and click the
    "Download" link. It's a simple HREF Anchor Tag, but the HTTP Response
    does set the Content-Disposition header, here's an excerpt from a
    response to a click on one of my images:

    HTTP/1.0 200 OK
    Date: Fri, 01 Jun 2007 08:12:34 GMT
    Server: Apache/2.0.52 (Red Hat)
    Content-Disposition: attachment;
    filename=516875174_4be52f4dbd_b.jpg <---- LOOK RIGHT HERE
    Pragma: no-cache
    Expires: 0
    Last-Modified: Sun, 27 May 2007 23:30:50 GMT
    Accept-Ranges: bytes
    Content-Length: 396060
    Content-Type: image/jpeg <--- ALWAYS A GOOD IDEA TO SET PROPER
    MIMETYPE AS Content-Type header value
    X-Cache: MISS from photocache3.flickr.mud.yahoo.com





    On May 31, 9:55 pm, Randy Webb <HikksNotAtH...@aol.com> wrote:
    > Lee said the following on 5/31/2007 10:04 PM:
    >
    > > pd said:

    >
    > >> please help me. all i want the user to be able to do is, to download
    > >> the file, and they can either go right click and save target or just
    > >> click on it and the download dialog should pop up. thanks.

    >
    > > That's not the way browsers are supposed to work. The browser
    > > should display the file that you click on in the window if it
    > > knows how. Only if it doesn't know how (or knows that it isn't
    > > safe to try), should it offer to download the contents. Unless,
    > > of course, the server tells the browser that the file should
    > > take some other action.

    >
    > Or, the user has explicitly told the browser how to handle a particular
    > file. IE and FF both have that setting available to the user.
    >
    > --
    > Randy
    > Chance Favors The Prepared Mind
    > comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
    > Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/




+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 10-29-2007, 03:10 PM
  2. a simple JButton and some output text on file. Doesn't work...
    By Application Development in forum Java
    Replies: 0
    Last Post: 07-30-2007, 09:31 AM
  3. Link to local file doesn't work when accessed through server. Why?
    By Application Development in forum Inetserver
    Replies: 1
    Last Post: 05-27-2006, 09:10 AM
  4. RUS doesnt work
    By Application Development in forum Microsoft Exchange
    Replies: 24
    Last Post: 03-13-2006, 03:09 PM
  5. Save link target button wont work
    By Application Development in forum Adobe Acrobat
    Replies: 0
    Last Post: 10-21-2005, 09:23 AM