二进制文件发送到浏览器后关闭弹出窗口

发布于 2024-08-14 08:36:20 字数 585 浏览 6 评论 0原文

有没有办法在页面将二进制数据(PDF)写入浏览器后关闭弹出窗口?

详细信息如下:

每当我的网络应用程序需要打印时,它都会将一些参数传递到弹出窗口,该窗口将显示打印选项。当用户单击“打印”按钮时,它将设置 iframe 的 src,该 iframe 将调用执行打印的页面。

我有 PDFConverter 将 URL / HTML 转换为 pdf 文件。转换结束时,它将二进制文件写入浏览器。以下是一些代码:

response.AddHeader("Content-Type", "binary/octet-stream");
response.AddHeader("Content-Disposition",
"inline; filename=" + fileName + ".pdf; size=" + pdfBytes.Length.ToString());
response.Flush();
response.BinaryWrite(pdfBytes);
response.Flush();

完成后,我需要关闭弹出窗口。然而,在响应被刷新后,你似乎无法做任何事情。有什么想法吗?

提前致谢!

安吉拉

Is there a way to close a pop up window after the page writes binary data (PDF) to the browswer?

Here are the details:

Whenever my web appilcation needs to print, it will pass some parameters over to a pop up window, which will display the print options. When the user clicks on the Print button, it will set the src of a iframe that will call the page that does the printing.

I have PDFConverter to convert URL / HTML to a pdf file. At the end of the converting, it will write the binary to the browser. Here are some code:

response.AddHeader("Content-Type", "binary/octet-stream");
response.AddHeader("Content-Disposition",
"inline; filename=" + fileName + ".pdf; size=" + pdfBytes.Length.ToString());
response.Flush();
response.BinaryWrite(pdfBytes);
response.Flush();

After this is done, i will need to close the pop up window. However it seems like you can't do anything after the response is flushed. Any ideas?

Thanks in advance!

Angela

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浪漫人生路 2024-08-21 08:36:20

您可以在父窗口中创建它,而不是在弹出窗口中创建它。这样,一旦用户单击打印按钮,您就可以安全地关闭弹出窗口,而无需中断打印过程。但是,我不会经历创建可能被某些浏览器阻止的新弹出窗口的所有痛苦,而是只需在主页中创建一些占位符,以便用户可以选择打印选项,然后打印文档。

Instead of creating the iframe in the popup window, you could create it in the parent window. This way once the user clicks the print button, you could safely close the popup without interupting the printing process. But instead of going through all the pain of creating new popups windows which might be blocked by some browsers, I would simply create some placeholder in the main page so that the user could choose printing options and then print the document.

悲歌长辞 2024-08-21 08:36:20

以防万一其他人也遇到同样的问题。这似乎是对我有用的解决方案。

我使用 jQuery Simple Modal 来显示我的选项列表页面。在此页面上,我有一个窗口计时器每 1 秒运行一次,以检查服务器是否完成打印作业。我为此使用ajax。工作完成后,我更新会话变量,对服务器的 ajax 调用将获取会话值并关闭弹出窗口。

Just in case anyone else is having the same problem. This is the solution that seems to work for me.

I use the jQuery Simple Modal to show my option list page. On this page, I have a window timer running every 1 second to check against the server if the print job is done. I use ajax for that. Once the job is done, I update the session variable, and the ajax call to the server will pick up the session value and close the pop up window.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文