【问题标题】:Is it possible to add 2 Response.Redirect, one will open in different tab and other one will open in same tab, using C#?是否可以使用 C# 添加 2 个 Response.Redirect,一个将在不同的选项卡中打开,另一个将在同一选项卡中打开?
【发布时间】:2017-01-27 07:41:10
【问题描述】:

当用户单击按钮时,我想在不同的选项卡中打开一个 .aspx/.html 页面,并在同一个选项卡中打开一个 .aspx/.html 页面。

示例代码:

string redirect = "<script>window.open('../User/Profile.html');</script>";
Response.Write(redirect);
Response.Redirect("../User/NewUser.aspx",true);

感谢 Adance !!!

【问题讨论】:

标签: c# response.redirect new-window


【解决方案1】:

此代码无法在 Chrome 上运行:

window.location.href = '../User/NewUser.aspx';

但您可以使用此代码代替window.location.href,然后它可以在所有浏览器中使用:

setTimeout(function(){document.location.href = "page.html"},500);

【讨论】:

    【解决方案2】:

    我们可以通过使用Javascript和页面背后的代码来实现

    在 Clientclick 属性上调用 Javascript Window.Open() 函数以在新窗口中打开。

    并且 onClick 调用你的代码在 buttonClick 事件后面重定向到同一个窗口。

    ASPX 页面:

      <asp:Button ID="Button1" runat="server" Text="Button"   OnClick="Button1_Click" OnClientClick="javascript:window.open('http://google.com','_blank');return true;" />
    

    点击功能背后的代码:

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("http://google.com");
    }
    

    【讨论】:

    • 您好,感谢您的回答。我不能这样做,因为我必须在重定向到两个页面之前执行代码。
    【解决方案3】:

    不,响应重定向在 http 的标头中写入“位置”值,并且只能有一个,但您可以编写一个类似下一个的 javascript 来做您需要的事情:

    window.open('../User/Profile.html', 'tabName');
    window.location.href = '../User/NewUser.aspx';
    

    祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多