Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open two separate (default) browser windows instead of new tabs

I'm trying to use C# to open two separate browser windows side by side. I've tried using Process.Start(url) but that causes Chrome to open new tabs instead of new windows. This seems to work on IE, however I'd like to have code that can work with different types of browsers, namely: IE, Chrome, Firefox, and Safari. How do I detect the default browser and then open two separate windows side-by-side? Additionally, I want to be able to position the two windows next to each other, is that possible?

like image 478
user1715925 Avatar asked Oct 31 '12 02:10

user1715925


2 Answers

If you want to open new window in chrome instead of new tab, this code worked for me

  Process process = new System.Diagnostics.Process();
  process.StartInfo.FileName = "chrome";
  process.StartInfo.Arguments = <yoururl> + " --new-window"; 
  process.Start();
like image 157
Guillermo Zooby Avatar answered Nov 10 '22 22:11

Guillermo Zooby


This is more about the way that the browser is configured than how the process is called from C#. In both cases, the system simply calls the default program assigned to handle the URL. There may or may not be arguments to that command, but typically it will simply invoke chrome.exe <url> and from there, the chrome.exe process decides how to handle the parameter.

The only method I am aware of would be to examine the registry (under HKEY_CLASSES_ROOT\http\shell\open\command) and parse the string value. Once you know the specific browser, you may be able to control the presentation using command-line arguments. Of course, this is specific to Windows and may be a pain to manage.

If the browser does not support setting a geometry from the command line, you will need to use FindWindow and SetWindowPos (using P/Invoke) to manipulate the window locations.

I am not sure about your application, but would embedding a WebBrowser Control meet your needs? Then you would have total control of the presentation.

like image 1
jheddings Avatar answered Nov 10 '22 21:11

jheddings