title: Closing a pop-up window after writing file to response
body: <p>In my code, I am using JavaScript to fire off an <code>window.open()</code> event on an ASPX page. I´m outputting a file in the <code>Page_Load()</code> event of this page:</p>
  
  <pre><code>Response.Clear();
  Response.ClearContent();
  Response.ClearHeaders();
  Response.Charset = "";
  Response.ContentType = "application/octet-stream";
  Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\";");
  outputStream.WriteTo(Response.OutputStream);
  outputStream.Flush();
  outputStream.Close();
  Response.Flush();
  Response.Close();
  </code></pre>
  
  <p>Afterwards i want to close this popup window. But because I have changed my response type, I cant execute <code>window.close()</code> in JavaScript. It will just get appended to the file being given to the users. This thread is the most suitable source i found to solve my problem:</p>
  
  <p><a href="http://forums.asp.net/t/1186371.aspx?PageIndex=1" rel="nofollow noreferrer">Closing window after export to excel</a></p>
  
  <p>But the given answers dont help me, so i am basically stuck. I dont want to tell the user to close the window manually. Do you know how to achieve what i aim for?</p>