如何在c#上打开新的选项卡,并专注于当前页面,然后当前页面重定向到另一个页面点击按钮

本文关键字:当前页 然后 重定向 按钮 另一个 专注 选项 | 更新日期: 2023-09-27 17:51:13

我已经试过这个代码了:

 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),浏览器打开新的选项卡,但焦点到新的选项卡。

有谁能帮忙吗?

如何在c#上打开新的选项卡,并专注于当前页面,然后当前页面重定向到另一个页面点击按钮

是的,您应该删除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);