how to open a page in new tab on button click in asp.net?

前端 未结 16 1882
情书的邮戳
情书的邮戳 2020-11-29 07:32

I want to open a page in new tab of browser on button click.

I have searched a lot on google but i couldn\'t find anything.

Here is my button.



        
相关标签:
16条回答
  • 2020-11-29 08:05

    Take care to reset target, otherwise all other calls like Response.Redirect will open in a new tab, which might be not what you want.

    <asp:LinkButton OnClientClick="openInNewTab();" .../>
    

    In javaScript:

    <script type="text/javascript">
        function openInNewTab() {
            window.document.forms[0].target = '_blank'; 
            setTimeout(function () { window.document.forms[0].target = ''; }, 0);
        }
    </script>
    
    0 讨论(0)
  • 2020-11-29 08:07

    Why not just call window.open straight from OnClick?

    <asp:Button ID="btnNewEntry" runat="Server" CssClass="button" Text="New Entry" OnClick="window.open('New.aspx')" />
    
    0 讨论(0)
  • 2020-11-29 08:12

    try this rather than redirect...

    Response.Write("<script>");
    Response.Write("window.open('ClickPicture.aspx','_blank')");
    Response.Write("</script>");
    
    0 讨论(0)
  • 2020-11-29 08:13

    A simple solution:

    <a href="https://www.google.com" target="_blank">
        <button type="button">Open new tab</button>
    </a>
    
    0 讨论(0)
提交回复
热议问题