[英]How Open New Browser Window
我正在使用 Asp.net c# 開發 web 應用程序
如何在新瀏覽器 window 中打開 response.redirect?
例如響應。重定向( http://www.asp.net );
謝謝
這是一個很常見的問題,答案是你不能。
原因是瀏覽器何時將請求發送到將加載頁面的服務器已經確定,因此當代碼開始在服務器上運行時,更改頁面的加載位置為時已晚。
您可以將 javascript 添加到將打開新 window 的頁面,但您仍然必須將頁面發送回瀏覽器作為對請求的響應(即您不能將當前頁面留在瀏覽器中,因為瀏覽器已經已經請求了一個頁面來替換它)。
ClientScript.RegisterStartupScript(this.GetType(), "aspnet", "window.open('http://www.asp.net','_blank');", true);
不幸的是,您無法從服務器執行此操作,您將不得不使用客戶端代碼來創建新的瀏覽器 window。 您可以使用 Javascript function window.open
來做到這一點。
One way of doing this would be to embed the URL you wish to send the user to in a hidden input and then when the page renders have a Javascript function that would check that input for a value and if it found one it would do the window.open
通話。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.