下载完成后关闭窗口-ASP

时间:2014-01-10 08:47:57

标签: asp-classic

我有这个功能,用于在本地磁盘中保存PDF文件。

如何在下载完成后使用alert / msg框自动关闭窗口,说明窗口将关闭?

这不起作用:

Response.Write ("<script>alert('Save Finished'); self.close();</script>")

导出代码:

Private Function SaveLocal1(ByRef cnCon, ByVal PDFFile)
    Dim ObjStream
    Dim ObjFileSys
    Dim Size
    Dim fpath
    Dim bdata

    'Response.Write("<script>alert('local');</script>")

    fpath = "C:\1.pdf" 'path of the file in the local server
    filename = "LocalSave.pdf"     'name to be saved
        'Response.Write("<script>alert('file paths');</script>")

    Set ObjStream = Server.CreateObject("ADODB.Stream")
    ObjStream.Open
    ObjStream.Type = 1
    ObjStream.LoadFromFile fpath
        'Response.Write("<script>alert('server.createobject');</script>")

    Response.buffer = TRUE
    Response.AddHeader "Content-Disposition","attachment;filename="& filename & ";"
    Response.ContentType = "application/pdf"

    Set ObjFileSys =  CreateObject("Scripting.FileSystemObject")
    Size = ObjFileSys.GetFile(fpath).Size

    bdata = ObjStream.Read(Size)

    Response.BinaryWrite(bdata)     'the file will be saved in the downloads folder

    Response.Write("<script>alert('Save to local finish');</script>")
    ObjStream.Close
    Set ObjStream = Nothing    

    Response.Flush
    Response.End
    Response.Write ("<script>alert('Save Finished'); self.close();</script>")
End Function

1 个答案:

答案 0 :(得分:3)

我想您的代码中可能存在2个问题。

第二期:

Response.End
Response.Write ("<script>alert('Save Finished'); self.close();</script>")

Response.End - 是最后一个命令。就这些。 “文件”完成。

  

End方法使Web服务器停止处理脚本和   返回当前结果。该文件的其余内容不是   处理。

将以下命令的顺序更改为

Response.Write ("<script>alert('Save Finished'); self.close();</script>")
Response.End