<SCRIPT LANGUAGE="JavaScript">
function saveTo ()
{
var w = window.open("image001.gif");
w.document.execCommand('SaveAs', null, 'image001.gif');
w.close();
}
</script>
<img src="image001.gif" width="543" height="492" border=0 alt="click to save" onclick="saveTo()">
function saveTo ()
{
var w = window.open("image001.gif");
w.document.execCommand('SaveAs', null, 'image001.gif');
w.close();
}
</script>
<img src="image001.gif" width="543" height="492" border=0 alt="click to save" onclick="saveTo()">
有歌大侠写的download的文件,可以直接传递参数给该文件,
然后该文件会提示用户保存指定得文件,而且可以下载ie都能默认显示
得word文档等。
<%@ Language=VBScript %>
<%
Dim filename
filename = Trim(Request("filename"))
if filename<>"" and not isnull(filename) then filename=Replace(Replace(filename,"/",""),"\","")
call downloadFile(filename)
Function downloadFile(strFile)
strFilename = server.MapPath(strFile)
Response.Buffer = True
Response.Clear
Set s = Server.CreateObject("ADODB.Stream")
s.Open
s.Type = 1
' load in the file
on error resume next
' check the file exists
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
Response.End
end if
' get length of file
Set f = fso.GetFile(strFilename)
intFilelength = f.size
s.LoadFromFile(strFilename)
if err then
Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
Response.End
end if
' send the headers to the users browser
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite s.Read
Response.Flush
s.Close
Set s = Nothing
End Function
%>
〉〉可以,道理一样的。
to 一刺:
你的方法虽然有用,但是调用的是ie中另存为的功能。如果附件为操作系统未识别的文件类型,另存的时候可能导致文件后缀名改掉。另外还有弹出的对话框也是另存的窗口,最下面还有选择语言的项。
在ie中选中附件的时候,右键单击弹出菜单中有目标另存为一项,不知道大家能不能做到象这样的功能。