弹出窗口中的 Response.BinaryWrite 和 Response.Write
我在模态窗口中。
我有一个指向 ashx 文件的超链接。
这个 ashx 文件使用 Response.BinaryWrite 推送文件进行下载,然后我想关闭模式。
问题是
如果我使用
Response.BinaryWrite(myFile);
Response.("<script type='text/javascript'>window.close();</script>");
它就不起作用。
如果我更不用说
Response.("<script type='text/javascript'>window.close();</script>");
它有效了。
任何机构对此有解决方案吗?
谢谢
I am in a modal window.
I have an hyperlink which points on an ashx file.
this ashx file use Response.BinaryWrite to push the file for download and I then want to close the modal.
the things is that
if I use
Response.BinaryWrite(myFile);
Response.("<script type='text/javascript'>window.close();</script>");
it does not work.
if I let alone
Response.("<script type='text/javascript'>window.close();</script>");
it works.
Any body having a solution for this ?
thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,没有解决方案,因为上面的行做了两个不同的事情:
第一行基本上是将文件流式传输给用户。在用户响应出现的对话框(他选择保存或在屏幕上显示它)之前,您无能为力。您似乎正在尝试自动关闭用户的对话框,但您无法从服务器端代码控制用户的浏览器。
第二行之所以有效,是因为您所做的只是发送指示浏览器窗口自行关闭的 javascript 代码。您不能将这两件事交织在同一个响应流中。
No, there's no solution because your lines above do two different things:
The first line is basically streaming a file to the user. Until the user responds to the dialog that appears (he either chooses to save or display it on the screen) there's nothing you can do. It seems you are attempting to close the user's dialog automatically but you can't control the user's browser from server side code.
The second line works because all you are doing is sending javascript code that instructs the browser window to close itself. You can't intertwined these 2 things in the same response stream.
我认为您选择了错误的方法。 AFAIK 您使用二进制写入将二进制内容发送到客户端,即 pdf
客户端不会理解您还在二进制流末尾发送了 javascript。
您不能将二进制数据和脚本结合起来
I think you are choosing a wrong approach. AFAIK you use a binary write to send something binary to the client i.e. a pdf
The client will not understand that you also send a javascript at the end of a binary stream.
You can not combine the binary data and the script