Click to See Complete Forum and Search --> : Download Script


ss_lee
12-12-2002, 03:22 AM
How to create a download button by using JAVA Script that allow user to download my files from my site to their PC?

Charles
12-12-2002, 09:53 AM
Though, perfectionists will use:

<a href="myfile.zip" type="application/zip">myfile.zip</a>

See ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/media-types for the official list of media types.

davidman73
12-12-2002, 10:13 AM
Well, I have a similar problem. A Client wants to have the possibility to click a PDF to open it on IE or download it to his computer. Clicking on a PDF will always open it (unless they configure it otherwise). They don't want the zipped version.

Is there a way to invoke the download form for the PDF using javascript?

Charles
12-12-2002, 10:16 AM
You could try changing the MIME type in the HTTP response header to "application/octet-stream" if you cannot convince your client that it's impolite to over-ride user's preferences.

davidman73
12-12-2002, 11:59 AM
Not working....:(

Maybe I didn't understand. This is what I did:

<a href="http://...." type="application/octet-stream">Whatever</a>

Is that what you mean?

Charles
12-12-2002, 02:38 PM
As a part of the behind the scenes communication that goes on between browsers and servers, each web resource has an HTTP response header that is generated by the server. The header for http://www.w3.org/ looks like:

HTTP/1.1 200 OK
Date: Thu, 12 Dec 2002 20:32:33 GMT
Server: Apache/1.3.26 (Unix) PHP/3.0.18
Content-Location: Overview.html
Vary: negotiate,accept
TCN: choice
P3P: policyref="http://www.w3.org/2001/05/P3P/p3p.xml"
Cache-Control: max-age=600
Expires: Thu, 12 Dec 2002 20:42:33 GMT
Last-Modified: Tue, 10 Dec 2002 15:12:28 GMT
ETag: "3df6045c;3df4a48d"
Accept-Ranges: bytes
~~~~~~~~~~~~~~: ~~~~~
Connection: close
Content-Type: text/html; charset=utf-8

It's that last line that we need to change, methinks. But how you do that will depend upon the server that you are using, so talk to your server f&uuml;hrer.