javascript - 从 ASP.NET 项目中在新选项卡中打开外部链接

标签 javascript c# html asp.net

我计划在单击按钮时从我的 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 页面未找到..

enter image description here

最佳答案

注意所请求的 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/

相关文章:

javascript - 是否可以连接 KML 图层以在一个复选框(Google map )中显示它们?

javascript - 如何重新选择已经选择的选项

javascript - 如何使用嵌套 <ul> 创建选项卡组?

javascript - 如何访问订阅 channel 的人员列表?

javascript - node.js中的异步for循环

c# - 如何将光标焦点设置到文本框?

C#.NET - 使用 HMAC-SHA512 签名 HTTP POST 消息在某些系统中会产生不一致的结果

javascript - 可湿性粉剂 : make the <section> clickable for certain post types

javascript - 什么是 "event emitter"?

c# - 使用 mongodb 和指南作为文档 ID 存储指南以轻松检索实际 Guid 的有效方法是什么?