title: close window when download finish-ASP
body: <p>I have this function made to save a PDF file in the local disk.</p>
  
  <p>How do I automatically close the window after the download completed with an alert/msg box stating that the window will close? </p>
  
  <p>This doesn't work:</p>
  
  <pre><code>Response.Write ("&lt;script&gt;alert('Save Finished'); self.close();&lt;/script&gt;")
  </code></pre>
  
  <p>TheCode:</p>
  
  <pre><code>Private Function SaveLocal1(ByRef cnCon, ByVal PDFFile)
      Dim ObjStream
      Dim ObjFileSys
      Dim Size
      Dim fpath
      Dim bdata
  
      'Response.Write("&lt;script&gt;alert('local');&lt;/script&gt;")
  
      fpath = "C:\1.pdf" 'path of the file in the local server
      filename = "LocalSave.pdf"     'name to be saved
          'Response.Write("&lt;script&gt;alert('file paths');&lt;/script&gt;")
  
      Set ObjStream = Server.CreateObject("ADODB.Stream")
      ObjStream.Open
      ObjStream.Type = 1
      ObjStream.LoadFromFile fpath
          'Response.Write("&lt;script&gt;alert('server.createobject');&lt;/script&gt;")
  
      Response.buffer = TRUE
      Response.AddHeader "Content-Disposition","attachment;filename="&amp; filename &amp; ";"
      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("&lt;script&gt;alert('Save to local finish');&lt;/script&gt;")
      ObjStream.Close
      Set ObjStream = Nothing    
  
      Response.Flush
      Response.End
      Response.Write ("&lt;script&gt;alert('Save Finished'); self.close();&lt;/script&gt;")
  End Function
  </code></pre>