2014-10-02 59 views
1

我有一個HTTPHandler執行一個小的工作單元。我沒有「輸出」我想要顯示。有沒有從代碼關閉瀏覽器窗口,因爲我離開子的方法:即對最終用戶重要通過電子郵件發送工作單位的作爲一個HTTPHandler.ashx完成ProcessRequest如何關閉瀏覽器窗口與代碼

Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest 
' unit of work 
' would like to close browser window here 
End Sub 

詳細信息。有沒有簡單的方法來關閉瀏覽器窗口(或選項卡)與代碼(如果可能,沒有Javascript)?

UPDATE:

我嘗試這樣做:

context.Response.Write("<script>window.open('', '_self', ''); window.close();<script>") 

隨着谷歌Chrome,我剛剛回來的代碼作爲消息(不是 「行動」 的預期)。還有更多需要被包裹進Response.Write還是我誤解了某些東西?

UPDATE NO.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> 

谷歌瀏覽器的調試器提供了這個錯誤:

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中使用它,那麼我會放棄,只是吐出一個簡單的迴應。仍在研究這裏。

回答

1

通過JavaScript關閉窗口將是唯一的出路,所以你必須編寫如下,以響應:

string closeWindow = @"<html><head></head><body><script>window.open('', '_self', ''); window.close();</script></body></html>"; 
context.Response.Write(closeWindow); 

第一條語句防止幾乎所有的瀏覽器的提示。

+0

謝謝。請看我的更新作爲後續。 – 2014-10-02 19:38:51

+0

@JohnAdams,腳本必須在html頁面才能執行。看到我更新的答案。 – 2014-10-02 19:55:42

+0

非常感謝。顯然這個問題更多。請參閱我的第二次更新。以爲你應該知道我的立場,我非常感謝你的快速幫助。 – 2014-10-02 20:43:27