方法 : 你可以把超链的href=目标定位到一个asp页面(不显示/无html/body) 在该页面编写下载 文件的代码 也可以在该asp页面得到上页传的值 判断下载文件名...2:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD><BODY>
<img src="2.BMP" onclick="mm(this)"><SCRIPT LANGUAGE="JavaScript">
function mm(e) //这个方法只针对图片
{
var w = window.open(e.src, "_blank", "width=100,height=100");
w.document.execCommand('Saveas');
w.close()
}
</SCRIPT>
<a href="#" onclick="download();">文件一下载</a><script language="JavaScript">
<!--
function download(){
var win=window.open("操作步骤.txt");
win.document.execCommand("saveas");
win.close();
}
//-->
</script></BODY>
</HTML>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD><BODY>
<img src="2.BMP" onclick="mm(this)"><SCRIPT LANGUAGE="JavaScript">
function mm(e) //这个方法只针对图片
{
var w = window.open(e.src, "_blank", "width=100,height=100");
w.document.execCommand('Saveas');
w.close()
}
</SCRIPT>
<a href="#" onclick="download();">文件一下载</a><script language="JavaScript">
<!--
function download(){
var win=window.open("操作步骤.txt");
win.document.execCommand("saveas");
win.close();
}
//-->
</script></BODY>
</HTML>
解决方案 »
- JSP+ACCESS:用复选框删除留言功能?
- 双网卡的电脑,如何获取主机IP地址
- *******************怎样才能document.write出\u1100-\u11FF区间的字符呢???
- js有关的问题document.execCommand
- 日期:YYYYMMDD和時間:HHMMDD的正則表達式分別是什么?
- 如何自动对校友录留言?
- 菜鸟跪问一个简单的javaSript的问题
- 为什么一个链接蹦出两个页(急?)
- 各位大侠,谁有关于网页左右分栏,左栏可用图标控制隐现的javascript代码么?
- 画3个统计不同数字的饼图
- 如何实现双击左边的下拉框内容后,其内容被添加到右边的下拉框中?
- 如何使页面中的字体都比原来页面字体小一级?
如果想要客户下载,可以将内容打包成rar或者zip
只能下载本页面吧,我想下载链接中的文件怎么办,而且文件的格式不相同
Response.Clear
dim url
Dim fso,fl,flsize
dim Dname
Dim objStream,ContentType_temp,flName
Dname=trim(request("n")) '下载文件名
If Dname<>"" Then
url=server.MapPath("/")&"\"&Dname '下载文件存放的服务端目录
Set fso=Server.CreateObject("scripting.FileSystemObject")
Set fl=fso.getfile(url)
flsize=fl.size
flName=fl.name
Set fl=Nothing
Set fso=Nothing
%>
<% Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile url Select Case lcase(Right(flName, 4))
Case ".asf"
ContentType_temp = "video/x-ms-asf"
Case ".avi"
ContentType_temp = "video/avi"
Case ".doc"
ContentType_temp = "application/msword"
Case ".zip"
ContentType_temp = "application/zip"
Case ".xls"
ContentType_temp = "application/vnd.ms-excel"
Case ".gif"
ContentType_temp = "image/gif"
Case ".jpg", "jpeg"
ContentType_temp = "image/jpeg"
Case ".wav"
ContentType_temp = "audio/wav"
Case ".mp3"
ContentType_temp = "audio/mpeg3"
Case ".mpg", "mpeg"
ContentType_temp = "video/mpeg"
Case ".rtf"
ContentType_temp = "application/rtf"
Case ".htm", "html"
ContentType_temp = "text/html"
Case ".txt"
ContentType_temp = "text/plain"
Case Else
ContentType_temp = "application/octet-stream"
End Select Response.Charset = "UTF-8"
Response.ContentType = ContentType_temp Response.BinaryWrite objStream.Read
Response.Flush
response.Clear()
objStream.Close
Set objStream = Nothing
End If 'on error resume next
%>
<%
String fileName = request.getParameter("ID");
fileName=new String(fileName.getBytes("ISO8859_1"),"GBK");
int fileNameE=(int)(Math.random()*100+1);
response.setContentType("APPLICATION/OCTET-STREAM");
response.addHeader("content-type", "application/x-msdownload;");
response.setHeader("Content-disposition","attachment; filename=file" + fileNameE +".zip");//暂时不能处理中文文件名 a=response.encodeURL(fileName)
//上面這一行就是讓瀏覽器知道要用下載的方式來儲存檔案,檔名設定為test.doc
//如果要讓瀏覽器線上開啟檔案,那就把attachment改成inline就可以了
String path=application.getRealPath("")+"\\download\\"+fileName+".zip";
java.io.File file = new java.io.File(path);
java.io.FileInputStream fin = new java.io.FileInputStream(file);
//以上這行設定一個FileInputStream,參數設定檔案的原始路徑加檔名即可
OutputStream os=response.getOutputStream();
//取得response的OutputStream,以便等一下直接輸出檔案
byte[] b = new byte[1];
int j = 0;
while((j = fin.read(b)) > 0)
{
os.write(b);
}
os.close();
if (fin != null)
fin.close();
%>