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

Y

yihucd

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>
 
D

David Dorward

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

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.
 
N

Neredbojias

With neither quill nor qualm, (e-mail address 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.
 
T

Toby Inkster

yihucd said:
(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.
 
Y

yihucd

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>
 
D

David Dorward

<%
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.
 
Y

yihucd

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"

?
 
D

David Dorward

"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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top