0

I wrote a simple Java program to open a specific webpage when the program is run. I need to close it again after a given amount of time. Here is the function I wrote and am using to open the page:

public static void openWebpage(String uri) throws Exception {
    java.awt.Desktop.getDesktop().browse(new java.net.URI(uri));
}

Is there a way to close that webpage programatically? I already have another thread acting as a timer, so I simply need to close the webpage once the timer runs out.

DerStrom8
  • 1,311
  • 2
  • 23
  • 45
  • I think you might want to take a look at this http://stackoverflow.com/questions/29842930/close-browser-window-using-java-code – Dylan Meeus Nov 13 '15 at 13:33
  • Hmm, that might be exactly what I need. I'll give it a try. Thanks for the link! Surprised I didn't see that in my searches – DerStrom8 Nov 13 '15 at 13:41
  • Well it works to run the webpage but destroying the process does not close the webpage. – DerStrom8 Nov 13 '15 at 13:58
  • I take that back, it does work, but only if that webpage is the only one open. If I have others open it doesn't close anything – DerStrom8 Nov 13 '15 at 14:02
  • But is closing every webpage a good idea? If the user is using this browser for more than just your program, that would be rather inconvenient. – Dylan Meeus Nov 13 '15 at 14:02
  • Are you sure you want to do this? Closing a window automatically after a timeout is not a good user interface design. What if the user stepped away from the computer? What if the user was busy reading e-mail, or talking to someone? In general, if content is worth showing to the user in the first place, it's worth letting the user decide when he/she is done reading it. – VGR Nov 13 '15 at 14:26
  • I will be the only user, this is just a utility I'm writing to make my life easier. But I'm not sure if I want to close the entire browser, ideally I'd like to only close the webpage opened by the program, but wasn't sure if that was possible – DerStrom8 Nov 13 '15 at 15:02

0 Answers0