View Full Version : Creating a Hyperlink to a Download
hellocme
11-06-2002, 06:14 PM
First of all, I know very little about JavaScript. I hardly use it, so I never bothered to learn it. Currently I'm working on a page that requires a link the leads to a file to be downloaded. This script is what I thought would work, but it isn't...
javascript:Download()
Please help!
Thank you!
valeria_vi
11-06-2002, 06:22 PM
why don't you just put the link to the file in an <a> tag? teh browser should recognize the file type and begin teh download on its own. for example:
<a href="blah.doc"> should automatically open teh document in ms word.
<a href="blah.zip"> should automatically download teh ip file to your computer
krycek
11-06-2002, 06:22 PM
oh dear! :D
you don't need javascript, just put the url of the file you want to download inside a link tag.
<a href="myfiletodownload.mp3">Download myfile</a>
There are other ways, of course, but that one is very simple :)
::] krycek [::
beetle
11-06-2002, 06:26 PM
Previous topic (http://www.codingforums.com/showthread.php?s=&threadid=5085&highlight=force+save+as+dialog) regarding using JS to do this.
hellocme
11-06-2002, 06:26 PM
Thanks for the quick responses. :thumbsup:
When I use a regular hyplerlink, since it's a .txt file, it just opens in the window.
Any other suggestions?
glenngv
11-07-2002, 03:29 AM
<a href="view-source:http://mydomain/somefile.txt">View Text File</a>
replace appropriate absolute path of the text file
That will open the file in Notepad. Is this what you want?
If not and you want the download prompt displayed, you need a server-side language to do it. If you don't want, just zip the file and use a regular link.
hellocme
11-08-2002, 01:40 PM
I don't mean to sound totally dumb - but what is server side language?
Thanks! :thumbsup:
glenngv
11-11-2002, 03:16 AM
server-side language like ASP, JSP, PHP, etc
here is an article that tackles each of these languages.
http://www.webmasterbase.com/article/546
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.