0

I'd like to open an URL in the default browser using Java. So I am doing what the answer in this question says: Open a link in browser with java button?

It works. However, I want to automatically close that browser after some 10 seconds have passed (from Java). This is for Windows machines.

How can I achieve this?

Community
  • 1
  • 1
Saturn
  • 17,888
  • 49
  • 145
  • 271
  • 2
    Does this help : http://stackoverflow.com/questions/16015463/close-browser-from-java-code-using-specific-url-address or http://stackoverflow.com/questions/10075997/closing-a-web-browser-for-a-specific-url-from-the-java-program – StackFlowed May 21 '15 at 20:05

1 Answers1

0

Start the process with:

Process p = Runtime.getRuntime().exec(new String[] {"explorer", "http://google.pl"});

and after your 10 sec call:

    p.destroy();
Krzysztof Cichocki
  • 6,294
  • 1
  • 16
  • 32
  • Is killing a process like that not bad ? Eg. If the web browser wants to delete cookies on exit, will killing the browser process not prevent this ? Firefox shows a "restore tabs on crash" when it was killed, would this not have the same effect ? – Jonas Czech May 21 '15 at 20:21
  • Yes, the process will be killed. But In pure java you have only this way. – Krzysztof Cichocki May 22 '15 at 05:35