简体   繁体   English

如何在ASP 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?

I already tried this code: 我已经尝试过此代码:

 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);
    }

That code just redirect to another page, but if I remove Response.Redirect(url) , browser open new tab but focus to new tab. 该代码只是重定向到另一个页面,但是如果我删除Response.Redirect(url) ,浏览器将打开新选项卡,但将焦点放在新选项卡上。

Any body can help? 任何机构都能帮忙吗?

Yes, you should remove Response.Redirect(url); 是的,您应该删除Response.Redirect(url); , otherwise your code above it is lost. ,否则您上面的代码将丢失。 What browser are you using? 你使用的是什么浏览器? It's not only you code that controls this behaviour. 控制此行为的不仅是您的代码。 The browsers have settings for that too. 浏览器也有相应的设置。 For example, in Internet Explorer 11, go to Internet Options and click on the Tabs button on the general tab. 例如,在Internet Explorer 11中,转到“ Internet选项” ,然后在常规选项卡上单击“ 选项卡”按钮。 Notice the setting Always switch to new tabs when they are created , if it is checked, then it will behave the way you described it. 请注意,设置“ 总是在创建新标签时切换到新标签” ,如果选中该标签 ,它将按照您描述的方式进行操作。 Clear it and see what happens. 清除它,看看会发生什么。

You can open the page in a new window... 您可以在新窗口中打开页面...

ScriptManager.RegisterStartupScript(this, this.GetType(), "onclick", "javascript:window.open( '../../drupal/login.php','_blank','height=600px,width=600px,scrollbars=1');", true);

After that redirect to the required page... 之后,重定向到所需的页面...

Response.Redirect(url);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM