-1

I want to open 2 different browsers with the same link. I have found how to open the default browser, but I want to open a non default browser as well, and I can't seem to find a way.

  • You could use Runtime.exec(...) as other answers suggest. But it seems like a hacky solution. There may be a way to do it in SWT APIs though. – SomeDude Mar 14 '18 at 19:32
  • I suggest you look into [Selenium](https://www.seleniumhq.org). It provides lots of possibilities for browser automation. – Mick Mnemonic Mar 14 '18 at 19:34

1 Answers1

1

To open non default browser, you'll need to know where it is installed and what browser. After that you can open it using the following command:

Runtime rt = null;
rt =  Runtime.getRuntime();
rt.exec("<PATH TO FIREFOX>\\firefox.exe <WEBSITE TO OPEN>");


<PATH TO FIREFOX> = Path to whatever browser you need to open.
firefox.exe = Launcher for the browser.
<WEBSITE TO OPEN> = Website URL you are trying to open.

To open private browsing: Use tag -private-window

Example:

rt.exec("<PATH TO FIREFOX>\\firefox.exe -private-window <WEBSITE TO OPEN>");
clinomaniac
  • 2,200
  • 2
  • 17
  • 22
  • Ty this is exactly what I was looking for. Is there any way to also open a private version of the browser. There are different codes for each broser, i know, but where would I put that in the code? – Killer2294 Mar 14 '18 at 19:25
  • It would just be another argument. – clinomaniac Mar 14 '18 at 19:25
  • Happy to help, and welcome to Stack Overflow. If this answer or any other one solved your issue, please mark it as accepted. – clinomaniac Mar 14 '18 at 19:30
  • 1
    Yup I did do that, I had to give it a few minutes. Thank you so much it solved exactly what I needed – Killer2294 Mar 14 '18 at 19:34