Possible Duplicate:
Getting java gui to open a webpage in web browser - This is totally not a duplicate. I want to be able to reference a tab in the browser not just launch the browser.
I have a desktop application that has a button with an action that opens up a new browser with a specific URL. Every time I press the button it opens up a new window/tab. I want it to refresh the window/tab, if it is already open and if the URL is the same, instead of always opening a new one. The code to launch the initial window is pretty straight forward:
final String errMsg = "Error attempting to launch web browser";
String osName = System.getProperty("os.name");
try{
if (osName.startsWith("Windows"))
Runtime.getRuntime().exec( "rundll32 url.dll,FileProtocolHandler " + "www.stackoverflow.com");
}catch(Exception e){
JOptionPane.showMessageDialog(null, errMsg + "\n" + e.toString());
}
I was thinking maybe I could name the window/tab so when the code is launched it tries to find the name and refresh it if exists. But I am having troubles finding a solution like that. Additionally, is the way I am currently doing it acceptable?