在新窗口中打开链接

本文关键字:链接 在新窗口中打开 | 更新日期: 2023-09-27 18:37:08

我需要在新窗口中打开链接按钮中的链接。我有下面的代码,但它抛出了javascript错误。请帮忙

ASPX 代码:

<asp:LinkButton ID="Link" runat="server" CssClass="ReadOnlyLabel" 
                        CausesValidationn="false" OnClick="Link_Click"/>

代码隐藏

protected void Link_Click(object sender, EventArgs e)
{
   ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", 
                      "window.open(" + Link.Text + " ,'new_tab');", true);
}

在新窗口中打开链接

在这种情况下最好使用 Hypelink,它有目标选项来做到这一点:-

<asp:HyperLink ID="Link" runat="server" CssClass="ReadOnlyLabel" 
                  CausesValidationn="false" Target="_blank">Click Here</asp:HyperLink>

只需设置NavigateUrl属性即可设置窗口 url,并将Target属性设置为 _blank

试试这个

ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(),  
"window.open('" + Link.Text + "' ,'new_tab');", true);

编辑

ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(),  
@"window.open('https://www.google.co.in/' ,'new_tab');", true);

所以它变成了

ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(),  
"window.open('https://" + Link.Text + "' ,'new_tab');", true);

我是 aspx 的新手,但这肯定会感兴趣吗?

onclick="window.open (this.href, 'popupwindow', 'width=500,height=500,scrollbars,resizable')

http://forums.asp.net/t/1162787.aspx?How+to+open+hyperlink+in+new+window+without+any+tools+displayed+

这对

我有用

Uri uri = new Uri(LinkButton.Text);
ScriptManager.RegisterStartupScript(this, Page.GetType(), "", "window.open('" + uri.OriginalString + "');", true);