我计划在单击按钮时从我的 ASP.NET 项目中的“同一窗口的新选项卡”中打开外部链接(“www.google.com”)。有没有办法做到。 (链接来自数据库,看起来我无法在标记端执行此操作)。
目前我尝试过,response.redirect 和 window.open,但似乎都不起作用。
Response.Redirect
protected void btnSubmit_Click(object sender, EventArgs e)
{
Response.Redirect("www.google.com");
}
窗口.打开
protected void btnSubmit_Click(object sender, EventArgs e)
{
string x = "www.google.com";
string s = "window.open('" + x + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');";
ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
}
我在这两种情况下遇到的错误是:404 页面未找到..
最佳答案
注意所请求的 URL:
http://localhost/www.google.com
如果您将用户定向到另一个网站,则必须完全限定 URL:
Response.Redirect("http://www.google.com");
或者:
string x = "http://www.google.com";
否则浏览器会认为它正在当前站点上查找名为“www.google.com”的资源。
关于javascript - 从 ASP.NET 项目中在新选项卡中打开外部链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32427399/