2013-10-02 277 views
3

我想在加載自己的同時在新窗口中打開asp.net頁面。我試着用下面的代碼。但它在同一個窗口中打開,而不是在新窗口中打開。在新窗口中打開asp.net頁面

 protected void Page_Load(object sender, EventArgs e) 
    { 
     if (HttpContext.Current.Request.UserAgent != null) 
     { 
      var userAgent = HttpContext.Current.Request.UserAgent.ToLower(); 

      if (userAgent.Contains("iphone;")) 
      { 
       // iPhone 
       Form.Target = "_blank"; 

      } 


     } 
    } 

任何幫助表示讚賞。謝謝 !!

+0

http://stackoverflow.com/questions/16145187/how-to-open-a-page-in-a-new-window-or-tab-from-code-behind –

回答

7

在代碼中使用JavaScript背後重定向:

Response.Write("<script>window.open('http://www.google.com.hk/','_blank');</script>"); 

或者使用ScriptManager,你可以傳遞參數太多:

ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('YourPage.aspx?Param=" + ParamX.ToString() + "');",true); 

或者,如果你有一個按鈕,你可以如下使用它:

Button1.OnClientClick="javascript:window.open('YourPage.aspx?Param=" + ParamX.ToString() + "');"; 
0

這就是我所做的,只是試試這個

ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('ViewDetails.aspx','mywindow','menubar=1,resizable=1,width=900,height=600');", true); 
相關問題