Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 28th, 2005, 07:46 AM
Registered User
Join Date: May 2005
Location: Kolkata, West Bengal, India.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to kalyansarkar108
Default link to download a file

I have a jsp page that contains a link to a file. On clicking the link the file opens in the browser itself. I want to give an option "Would you like to open the file or save it to your computer?". How can I do this? Can anyone help?

Here is my code...

<td class="tbdataleft" align="left"><a href='file:C:/file.doc' class="red">file.doc</a></td>
Reply With Quote
  #2 (permalink)  
Old November 28th, 2005, 09:21 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts

The open/save dialogue appears automatically if the file is of a type the browser does not understand.

To force an open/save dialogue, you must alter the HTTP response headers. I don't know how it's done in JSP, but in PHP it looks like this:

// Put in whatever MIME type or leave this one
header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename=suggested_file_name.whatever');

// Grab and output the contents of the file.
echo file_get_contents('/server/path/to/file.whatever');


Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Encrypted URL download link benjamr Beginning PHP 1 October 5th, 2008 07:36 PM
How to provide download link for images snowbydave1 Beginning PHP 4 March 24th, 2007 04:38 AM
How to provide download link for images snowbydave1 Pro PHP 0 March 19th, 2007 02:06 AM
How to provide download link for images snowbydave1 PHP Databases 0 March 19th, 2007 02:04 AM

All times are GMT -4. The time now is 01:18 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.