How would I be able to open an URL in the same window in java?
This is my current code for the open URL part. How can I modify it so it always opens in the same browser window? This is not javascript.
try{
String url = "www.google.ca"+sn;
java.awt.Desktop.getDesktop().br开发者_StackOverflow中文版owse(java.net.URI.create(url));
}
catch (Exception e) {}
}
This function is called many times where sn is a random new page on google. How can i replace the current page it opens?
AFAIK, there is no general, portable, way to do this. Depending on the browser and the platform, you may be able to do non-portable things to tell an existing browser instance to open a different page. However, the standard Java APIs don't support this. (For a start, it may not be technically implementable for some browsers / platforms.)
Another approach might be to use an embedded Java browser; see Is there a way to embed a browser in Java?
精彩评论