How do I use Target=_blank on a response.redirect?

后端 未结 12 1920
梦谈多话
梦谈多话 2020-12-10 16:12

I do not necessarily have to use response.redirect, but that is what I had. I would like to open the selected link in a new window. How do I do that?

context         


        
相关标签:
12条回答
  • 2020-12-10 16:40

    You can't is the short answer. The browser is the only thing that can open up a new window.

    What you can do is send a chunk of html down the response that has a link with your url as an href, target="_blank" and a chunk of javascript onload of the form that fakes a click. If this doesn't work then use a window.open(url);

    response.write("<script>");
    response.write("window.open('page.html','_blank')");
    response.write("</script>"); 
    
    0 讨论(0)
  • 2020-12-10 16:41

    How about a hyperlink that you program dymanically? Imagine this. asp hyperlink that when you click opens a new window, possibly with no scroll bars, no address bar, anything you want. Here is an example:

    hyperlink1.Attributes.Add("onclick", "window.open(http://www.mylink.com?sessionvar1=" + someValue + "',null,'height=251px, width=600px,status=no, resizable=no, scrollbars=no, toolbar=no,location=no,menubar=no ');");
    

    This is just an alternative to a standard button that would otherwise call a click handler. Keep in mind, you can add the whole thing from the front as an attribute.

    0 讨论(0)
  • 2020-12-10 16:43

    You cannot do that with Response.Redirect()

    Well you could do this using a simple Javascript inside Response.Write

    Response.Write("<script>window.open('page.html','_blank')</script>");
    
    0 讨论(0)
  • 2020-12-10 16:43

    This works for me

    On aspx code:

     <a id="myLink" target="_blank" onclick="window.open('ExamplePage.aspx, '_blank');">Link To A Page And Open Other Tab</a>
    
    0 讨论(0)
  • 2020-12-10 16:50

    I added to @DaveWalker response:

    Response.Write("<script>")
    Response.Write("window.open('NewPage.aspx','_blank','resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=no')")
    Response.Write("</script>")
    

    This will create a popup instead of opening a new tab.

    0 讨论(0)
  • 2020-12-10 16:54

    I've seen many anwers and no one really works for me. So I tried the following code and it solved my problem:

    First I changed mt button by a linkbutton with the same aspect as a button.

    <asp:LinkButton ID="btPrint" runat="server" class="btn btn-primary"><span class="glyphicon glyphicon-print"></span> Print</asp:LinkButton>
    

    After this I add the following in my code behind.

    btPrint.Attributes.Add("href", String.Format("printPage.aspx?&id={0}", txtId.Text));
    btPrint.Attributes.Add("target", "_blank");
    
    0 讨论(0)
提交回复
热议问题