【发布时间】:2014-10-02 19:13:58
【问题描述】:
我有一个 HTTPHandler,它执行一个小的工作单元。我没有想要显示的“输出”。当我退出子程序时,是否有一种方法可以从代码中关闭浏览器窗口:
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
' unit of work
' would like to close browser window here
End Sub
对最终用户很重要的工作单元的详细信息通过电子邮件发送。有没有一种简单的方法可以用代码关闭浏览器窗口(或选项卡)(如果可能,不使用 Javascript)?
更新:
我试过了:
context.Response.Write("<script>window.open('', '_self', ''); window.close();<script>")
使用 Google Chrome,我只是将代码作为消息返回(不是预期的“操作”)。是否需要将更多内容包装到 Response.Write 中,还是我误解了什么?
第 2 条更新:
我还在研究。不能让它工作;即使使用 Response.Redirect 到以下 closeWindow.html 文件:
<!doctype html>
<html>
<head>
<title>
</title>
</head>
<body>
<script type='text/javascript'>
window.open('', '_self', '');
window.close();
</script>
</body>
</html>
Google chrome 调试器给出了这个错误:
scripts may only close the windows that were opened by it
没有其他事情发生。所以我搜索并找到了这个SO线程:
window.close and self.close do not close the window in Chrome
显然,还有更多。如果我不能让它在 Chrome 中工作,那么我将放弃并吐出一个简单的回应。还在这里研究。
【问题讨论】:
标签: asp.net httphandler