我已经检查各地的答案,这一个,但没有运气的地方。
我想要一个按钮或链接,将打开“另存为”对话框。 简单?
我知道我可以在新窗口/选项卡中打开的图像(因为我现在做的),然后用right-click, save as
的方法,但由于使用这个人是不是在框中锐利的刀,所以我想使下载尽可能简单。
目前的代码是:
<button class="downloadButton" type="submit" onClick="window.open('<%=(rsContent.Fields.Item("ContentImage").Value)%>')">Download Image</button>
但这将图像加载到一个新的窗口/新标签。
只是为了记录在案,用户使用的是Windows XP的Internet Explorer 8,所以我们不能用download
HTML5事件。
我不介意它的JavaScript,JQuery的或传统的ASP。
先谢谢您的帮助。
铅
UPDATE
使用MDN代码Lankymart贴,我想作为,是和它的工作(对于Excel文档的打开/下载),但是,我试图改变部分下载图片,并没有奏效。
这里是传统的ASP代码:
<%
Dim rsImage__imageID
rsImage__imageID = "1"
If (Request.QueryString("imageID") <> "") Then
rsImage__imageID = Request.QueryString("imageID")
End If
%>
<%
Dim rsImage
Dim rsImage_cmd
Dim rsImage_numRows
Set rsImage_cmd = Server.CreateObject ("ADODB.Command")
rsImage_cmd.ActiveConnection = MM_ENG_STRING
rsImage_cmd.CommandText = "SELECT ContentID, ContentImage, DisplayImage FROM tblContent WHERE ContentImage = ?"
rsImage_cmd.Prepared = true
rsImage_cmd.Parameters.Append rsImage_cmd.CreateParameter("param1", 5, 1, -1, rsImage__imageID) ' adDouble
Set rsImage = rsImage_cmd.Execute
rsImage_numRows = 0
%>
和(严重)改变MDN代码:
<%
'Set the content type to the specific type that you are sending.
Response.ContentType = "image/JPEG"
Const adTypeBinary = 1
Dim strImageFile
strImageFile = (rsImage.Fields.Item("ContentImage").Value) 'This is the path and name of the file on disk.
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strImageFile
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing
%>
我把它用:
<button class="downloadButton" type="submit" onClick="window.location.href='image-download.asp?imageID=<%=(rsContent.Fields.Item("ContentID").Value)%>';">Download Image</button>
它产生的错误是:
The image “http://localhost:85/admin/english/image-download.…p?imageID=5” cannot be displayed because it contains errors.
该页面的代码是:
<html>
<head>
<meta name="viewport" content="width=device-width; height=device-height;"></meta>
<link rel="stylesheet" href="resource://gre/res/ImageDocument.css"></link>
<link rel="stylesheet" href="resource://gre/res/TopLevelImageDocument.css"></link>
<link rel="stylesheet" href="chrome://global/skin/media/TopLevelImageDocument.css"></link>
<title>
image-download.asp (JPEG Image)
</title>
</head>
<body>
<img src="http://localhost:85/admin/english/image-download.asp?imageID=5" alt="The image “http://localhost:85/admin/english/image-download.…p?imageID=5” cannot be displayed because it contains errors." title=""></img>
</body>
</html>