![](/img/trans.png)
[英]asp.net: How to open a new asp.net page in new window (not tab or current page) using c#
[英]How to open new tab on ASP C# and focus stay on current page then current page redirect to another page on click button?
我已经尝试过此代码:
protected void btnLogin_Click(object sender, EventArgs e)
{
String username = tbxUserName.Text;
String password = tbxPassword.Text;
String url = "http://localhost/drupal/login.php?user_name="+username+"&password="+password;
Page.ClientScript.RegisterStartupScript(
this.GetType(),
"OpenWindow",
"var win = window.open('" + url + "','_newtab'); self.focus();",
true);
Response.Redirect(url);
}
该代码只是重定向到另一个页面,但是如果我删除Response.Redirect(url)
,浏览器将打开新选项卡,但将焦点放在新选项卡上。
任何机构都能帮忙吗?
是的,您应该删除Response.Redirect(url);
,否则您上面的代码将丢失。 你使用的是什么浏览器? 控制此行为的不仅是您的代码。 浏览器也有相应的设置。 例如,在Internet Explorer 11中,转到“ Internet选项” ,然后在常规选项卡上单击“ 选项卡”按钮。 请注意,设置“ 总是在创建新标签时切换到新标签” ,如果选中该标签 ,它将按照您描述的方式进行操作。 清除它,看看会发生什么。
您可以在新窗口中打开页面...
ScriptManager.RegisterStartupScript(this, this.GetType(), "onclick", "javascript:window.open( '../../drupal/login.php','_blank','height=600px,width=600px,scrollbars=1');", true);
之后,重定向到所需的页面...
Response.Redirect(url);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.