简体   繁体   中英

How to close window with apsx page?

I have a aspx page in window. Now i want to close it from cs code:

 string result = @"<script type='text/javascript'>
                    window.returnValue = true;
                   window.close();
                 </script>";
 Response.Write(result);

It's work fine.
Now i want to save a file and then close a window. And my code from above not work. I get a save file dialog, save a fine, but my window not close.
What i should do in this case?

SAVE FILE CODE

                File.WriteAllBytes(docFileName, documentStream.ToArray());

            fi = new FileInfo(docFileName);
            if (fi.Exists)
            {
                byte[] buffer;
                using (FileStream fileStream = new FileStream(docFileName, FileMode.Open))
                {
                    int fileSize = (int)fileStream.Length;
                    buffer = new byte[fileSize];
                    // Read file into buffer
                    fileStream.Read(buffer, 0, fileSize);
                    fileStream.Close();


                    fi.Delete();

                }


                Response.Clear();
                Response.Buffer = true;
                Response.BufferOutput = true;
                Response.ContentType = "application/x-download";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + docFileName);
                Response.CacheControl = "public";
                // writes buffer to OutputStream
                Response.OutputStream.Write(buffer, 0, buffer.Length);
                Response.End();

You cannot close the window like that.

You can only close the windows that was created by the script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM