Simple file link or button doesnt work

Discussion in 'Javascript' started by pd, Jun 1, 2007.

  1. pd

    pd Guest

    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.
    pd, Jun 1, 2007
    #1
    1. Advertising

  2. pd

    Lee Guest

    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.


    --
    Lee, Jun 1, 2007
    #2
    1. Advertising

  3. 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 <> 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/
    ChrisHolland@InternetBrands, Jun 1, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    897
  2. Replies:
    3
    Views:
    432
    alex23
    May 27, 2008
  3. Arthur Dent

    button in footer doesnt work?

    Arthur Dent, Mar 13, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    104
    Arthur Dent
    Mar 13, 2006
  4. Vince /.

    simple code doesnt work

    Vince /., Sep 20, 2006, in forum: Ruby
    Replies:
    4
    Views:
    123
    MonkeeSage
    Sep 20, 2006
  5. Aristotle

    why a simple $a =~ $b doesnt work ?

    Aristotle, Jul 17, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    79
    Tassilo v. Parseval
    Jul 17, 2004
Loading...

Share This Page