在C#中打开一个浏览器窗口弹出 [英] Open a browser window as a pop under in C#
问题描述
我试图让下用C#浏览器中打开一个弹出。基本上,我当浏览器被用户开始检测,我想之后立即打开一个新的浏览器窗口,是用户打开了窗下。这是我到目前为止有:
I'm trying to make a browser open as a pop under by using C#. Basically, I'm detecting when a browser is started by the user and I want to immediately after that open a new browser window which is under the window that the user opened. Here is what I have so far:
url = "example.com";
Process[] pname = Process.GetProcessesByName("chrome");
if (pname.Length == 0) // if the user didn't start chrome
{
chrome = false;
}
else // if chrome is running
{
if (!chrome) // if the browser wasn't opened before and it was opened just now.
{
Process process = new Process();
process.StartInfo.FileName = "chrome";
process.StartInfo.Arguments = url;
process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
process.Start();
//Process.Start("chrome", url);
}
chrome = true;
}
但这样做有时会打开一个新的窗口,有时在一个新的标签。也许我应该开始用浏览器之类的东西以不同的方式?谢谢!
But what this does is sometimes open it in a new window and sometimes in a new tab. Perhaps I should use a different way of starting a browser or something? Thanks!
推荐答案
当你调用(在这种情况下,Chrome浏览器)的外部程序,你必须遵循它的规律。通过在浏览器的参数(这里 名单)看, - 新窗口
提供你想要的东西。因此,你必须在你的code进行如下修改:
When you call an external program (Chrome in this case) you have to "follow its rules". By looking at the Chrome arguments (list here), --new-window
delivers what you want. Thus you have to perform the following change in your code:
process.StartInfo.Arguments = url + " --new-window";
如果你想完全控制,或许你应该建立自己的浏览器(的 web浏览器类,例如)。
If you want to have full control, perhaps you should create your own browser (WebBrowser Class, for example).
这篇关于在C#中打开一个浏览器窗口弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!