Java的桌面库可以在新的浏览器选项卡或窗口中启动URL吗? [英] Can Java's Desktop library launch a URL in a new Browser Tab or Window?
本文介绍了Java的桌面库可以在新的浏览器选项卡或窗口中启动URL吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个静态方法用于启动具有给定URL的浏览器。当浏览器已经打开时,它将接管活动的浏览器窗口。
I have a static method used to launch a browser with a given URL. When the browser is already open, this takes over the active browser window.
如果浏览器正在使用其他内容,例如数据输入,则会出现问题。有没有办法在新的浏览器窗口(或标签)中打开URL?
This is a problem if the browser is in use for something else, such as data entry. Is there a way to open a URL in a new Browser window (or tab)?
public static void openURL(String urlText)
{
if (Desktop.isDesktopSupported())
{
URI uri = URI.create(urlText);
try
{
Desktop.getDesktop().browse(uri);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
或者,有没有更好的这样做的方法?
Alternately, is there a better way to do this?
推荐答案
看看 BrowserLaunch2 。特别是此方法,用于强制打开新窗口。
Have a look at BrowserLaunch2. In particular this method for forcing a new window to be opened.
这篇关于Java的桌面库可以在新的浏览器选项卡或窗口中启动URL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文