aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Force a file download in HTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Force a file download in HTML" Watch "Force a file download in HTML" New topic
Author

Force a file download in HTML

Chethan Kumar Baliga
Greenhorn

Joined: Sep 17, 2002
Posts: 11
I am looking for a file download feature.
I have implemented the same using "href"
Ex: -
<a href="http://servername ort/folder/file.txt"> Download text file</a>
On click of this link however, the file directly opens in the browser window instead of being downloaded. Right-clicking on the link and selecting "Save Target As" is one option to download it.
What I am looking for is, ceratin file types (viz. zip, tif etc.) promptly show the "File Download" dialog box, others (viz. txt, html etc.) directly open in the browser window.
This is because of the "Content-type". There is some tag (meta or something else) where one can specify the "Content-type" OR "Content-disposition" so that the user is forced to download the file, no matter what (File Download should appear!!!). Does anyone have the exact code for this in simple HTML???
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I'm wondering if the 'a href' supports the 'type' attribute that exists in other tags...
<a href="..." type="application/unknown">... etc
Might be worth a try.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"Technical_User",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
Thanks.
Dave
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

if David's suggestion doesnt work, i would just compress(zip) any file you want to send rather than display


SCJP
Visit my download page
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Force a file download in HTML