Chr*_*ach 9 html javascript ms-office office-js
我有一个应用程序,显示一些静态文件供下载.此应用程序创建隐藏的iframe并将源设置为file-url.
浏览器显示另存为对话框.
但在Microsoft Office中没有另存为对话框,并且未启动filedownload.
该文件随附Content-Disposition: Attachment.工作解决方案只需打开一个新的浏览器实例并触发文件下载.我不想打开一个可以获得焦点的新窗口.
<!DOCTYPE html>
<html>
<head>
<script>
function di(){
document.getElementById("d").src="blob.dat";
}
</script>
<title>download</title>
</head>
<body>
<h1>file loading</h1>
<h2>works</h2>
<p>But opens a new window</p>
<a href="blob.dat" target="_blank"> a blank </a><br>
<a href="blob.dat" target="download"> named frame </a>
<h2>won't work</h2>
<a href="blob.dat"> a self </a><br>
<a href="blob.dat" target="_self"> a self </a><br>
<a href="blob.dat" target="_top"> a top </a><br>
<a href="#" onclick="di();"> iframe </a><br><br>
<iframe id="d"></iframe>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我认为这是一个严重的错误,如果网络应用程序无法跟踪链接.
小智 1
<script language="javascript">
function OpenADocument(strDoc)
{
document.blob.hidFLID.value=strDoc;
document.blob.action = "OpenLinksDocument.asp";
document.blob.method="post"
document.blob.submit();
}
</script>
Run Code Online (Sandbox Code Playgroud)
---- ASP 代码 ----
Private Sub DownloadFile(file, MainFileName)
'--declare variables
Dim strAbsFile
Dim strFileExtension
Dim objFSO
Dim objFile
Dim objStream, FileNM
strAbsFile = Server.MapPath(file)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strAbsFile) Then
Set objFile = objFSO.GetFile(strAbsFile)
strFileExtension = LCase(objFSO.GetExtensionName(file))
'-- first clear the response, and then set the appropriate headers
Response.Clear
'-- the filename you give it will be the one that is shown ' to the users by default when they save
dim NewFileName
NewFileName= "RandomFileNameYouWishtoGive" & Session.SessionID &"." &strFileExtension
Response.AddHeader "Content-Disposition", "attachment; filename=" & NewFileName
Response.AddHeader "Content-Length", objFile.Size
Response.ContentType = "application/octet-stream"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
'-- set as binary
objStream.Type = 1
Response.CharSet = "UTF-8"
'-- load into the stream the file
objStream.LoadFromFile(strAbsFile)
'-- send the stream in the response
Response.BinaryWrite(objStream.Read)
objStream.Close
Set objStream = Nothing
Set objFile = Nothing
Else 'objFSO.FileExists(strAbsFile)
Response.Clear
Response.Write("No such file exists.")
End If
Set objFSO = Nothing
End Sub
Run Code Online (Sandbox Code Playgroud)
解释:
1) 在“您的链接”页面上,不要在锚标记中提及您的文件名,
2)改为传递一些加密代码或加密文件名本身
3) 在您发布文件名的页面上,填写隐藏文件 ID 值的表单请求 - hidFLID
4)现在使用该文件名并将该文件名添加到响应标头中。
5) 这不会显示您的实际文件名,请在此处输入代码`me/文件路径
6) 上面的例子我已经指定是在经典ASP中,如果你提到你的Web技术,我可以帮助提供该技术中的代码。