问题
When user will click on button, I want to open one .aspx/.html page in different tab and open one .aspx/.html page in same tab.
Sample code:
string redirect = "<script>window.open('../User/Profile.html');</script>";
Response.Write(redirect);
Response.Redirect("../User/NewUser.aspx",true);
Thanks in Adance!!!
回答1:
No, the response redirect writes in the http's header the "location" value and can only have one, but you can write a javascript like the next for do what you need:
window.open('../User/Profile.html', 'tabName');
window.location.href = '../User/NewUser.aspx';
Good luck!
回答2:
We can achieve by using Javascript and code behind page
Call Javascript Window.Open() function on Clientclick property to open in new window.
and onClick call your code behine buttonClick Event to redirect on same window.
ASPX Page:
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" OnClientClick="javascript:window.open('http://google.com','_blank');return true;" />
Code behind On Click function:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("http://google.com");
}
回答3:
This code not working on Chrome :
window.location.href = '../User/NewUser.aspx';
But you can use this code instead of window.location.href
then its working in all browsers :
setTimeout(function(){document.location.href = "page.html"},500);
来源:https://stackoverflow.com/questions/39576169/is-it-possible-to-add-2-response-redirect-one-will-open-in-different-tab-and-ot