2016-09-19 60 views
1

当用户点击按钮时,我想在不同的选项卡中打开一个.aspx/.html页面,并在同一个选项卡中打开一个.aspx/.html页面。是否可以添加2 Response.Redirect,一个将打开在不同的选项卡,另一个将打开在同一个选项卡中,使用C#?

示例代码:

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

感谢Adance!

+0

潜在的重复数据删除:http://stackoverflow.com/questions/16896284/opening-a-url-in-a-new-tab –

+0

在这种解决方案,他们正在使用window.location.href那么它在所有浏览器工作的OnClientClick和OnClick方法。我不能这样做,因为我必须先执行.net代码,然后只重定向到两个页面。 – HP1104

回答

1

没有,响应重定向在HTTP的标题写道:“位置”值,只能有一个,但你可以写一个javascript喜欢下为你所需要的:

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

祝你好运!

+0

感谢您的解决方案。它工作完美。 – HP1104

0

我们可以通过使用JavaScript和代码页背后

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

和onClick调用您的代码behine 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"); 
} 
+0

你好,谢谢你的回答。我不能这样做,因为我必须在重定向到两个页面之前执行代码。 – HP1104

0

这个代码不工作在Chrome:

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

但是你可以使用这个代码

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