Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > how to write html tag to download a file intead of show content of file in browser

Reply
Thread Tools

how to write html tag to download a file intead of show content of file in browser

 
 
yihucd@gmail.com
Guest
Posts: n/a
 
      02-08-2006
I am write a html page that has one link on it. The purpose of the link
is to popup a window to let the user download/save the Excel file to
his/her local computer. But by using my code, when I click the link
"file" in the page, the content of the excel file showed in the browser
(I have firefox as my defult browser).

What I want is that : no matter what the user's default browser is,
when user click the link in the page, the browser should always pop up
a window to let the user save the file.
(because it is annoying to show some garbage in the browser window)

Thanks,

David



------------------------------------------my code --------
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>click file</title>
</head>

<body>

<p>click <a href="xls_to_del.xls">file</a></p>

</body>

</html>

 
Reply With Quote
 
 
 
 
David Dorward
Guest
Posts: n/a
 
      02-08-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> I am write a html page that has one link on it. The purpose of the link
> is to popup a window to let the user download/save the Excel file to
> his/her local computer.


<a href="foo.xls">Link Text</a>

> But by using my code, when I click the link "file" in the page, the
> content of the excel file showed in the browser


Then either your server is misconfigured and is claiming that your Excel
file is plain text (or HTML or something else that isn't Excel), or your
browser has the Excel plugin and is configured to use it.

> What I want is that : no matter what the user's default browser is,
> when user click the link in the page, the browser should always pop up
> a window to let the user save the file.


You /can/ use the Content-Disposition header to ask the browser to treat it
as an attachment rather than something to be displayed ... but I don't know
of any browser which doesn't have an option for the user to save the target
of a link instead of opening it with the default handler. If the user has
their browser set up to open Excel files in a plugin, then its likely to be
worth respecting that.

http://www.faqs.org/rfcs/rfc2183.html

> (because it is annoying to show some garbage in the browser window)


Sounds like its a case of the server claiming the Excel file is plain text.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
 
Reply With Quote
 
 
 
 
Neredbojias
Guest
Posts: n/a
 
      02-09-2006
With neither quill nor qualm, (E-Mail Removed) quothed:

> I am write a html page that has one link on it. The purpose of the link
> is to popup a window to let the user download/save the Excel file to
> his/her local computer. But by using my code, when I click the link
> "file" in the page, the content of the excel file showed in the browser
> (I have firefox as my defult browser).
>
> What I want is that : no matter what the user's default browser is,
> when user click the link in the page, the browser should always pop up
> a window to let the user save the file.
> (because it is annoying to show some garbage in the browser window)


Zip it.

--
Neredbojias
Contrary to popular belief, it is believable.
 
Reply With Quote
 
Toby Inkster
Guest
Posts: n/a
 
      02-09-2006
yihucd wrote:

> (because it is annoying to show some garbage in the browser window)


Configure your server to send it with the correct MIME type, which is:

application/vnd.ms-excel

If you don't know how to do this, ask your host.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

 
Reply With Quote
 
yihucd@gmail.com
Guest
Posts: n/a
 
      02-09-2006
Thank you all so much. I put following code in my JSP code.
But the thing is that, when I load this page, I only see the pop up
window without first seeing the acutal page.

What I want is a page showing the following sentence

" Click file"

When the user click on the word file, then a window pop up. How to do
this?

<%
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment; filename=" +
"xls_to_del.xls" );
%>


<html>

<head>
<title>click file</title>
</head>

<body>

<p>click <a href="xls_to_del.xls">file</a></p>

</body>

</html>

 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      02-09-2006
(E-Mail Removed) wrote:

> <%
> response.setContentType("application/vnd.ms-excel");
> response.setHeader("Content-Disposition","attachment; filename=" +
> "xls_to_del.xls" );
> %>
> <p>click <a href="xls_to_del.xls">file</a></p>


You need to send the Content-type that says "This is an Excel file!" when
you send the Excel file, not when you send an HTML document with a link to
the Excel file in it.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
 
Reply With Quote
 
yihucd@gmail.com
Guest
Posts: n/a
 
      02-09-2006
Hi David Dorward,

Can you detail how to

"send the Content-type that says "This is an Excel file!" when
you send the Excel file"

?

 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      02-09-2006
(E-Mail Removed) wrote:

> "send the Content-type that says "This is an Excel file!" when
> you send the Excel file"


Assuming you are using JSP, do exactly what you were doing, but replace the
HTML with the Excel data.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why ever use std_logic_vector intead of signed/unsigned? kevin.neilson@xilinx.com VHDL 11 02-23-2013 03:17 AM
LWP user agent grabs the intermediate wait page after POST intead ofthe actual result page bhabs Perl Misc 2 02-13-2008 01:55 AM
HTML.Tag.BASE same as HTML.Tag.A carlbernardi@gmail.com Java 1 11-29-2006 03:41 AM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Select text within a div tag by clicking on content of div tag? M Wells Javascript 0 10-06-2004 11:04 AM



Advertisments