我正在使用JWebBrowser作为Swing应用程序中的一个组件。当我单击JWebBrowser中的链接时,它会打开一个新窗口(window.open()javascript),但由Swing组件包装。我希望它在IE浏览器中打开!是否有JWebBrowser的任何属性允许这个?
答案 0 :(得分:1)
我遇到过类似的问题,大部分代码都来自原始示例: http://djproject.cvs.sourceforge.net/viewvc/djproject/DJNativeSwing-SWTDemo/src/chrriis/dj/nativeswing/swtimpl/demo/examples/webbrowser/NavigationControl.java?pathrev=R-1_0_1
browser.addWebBrowserListener(new WebBrowserAdapter() {
public void windowWillOpen(WebBrowserWindowWillOpenEvent e) {
// get the new swing window
final JWebBrowser newBrowser = e.getNewWebBrowser();
newBrowser.addWebBrowserListener(new WebBrowserAdapter() {
@Override
public void locationChanging(WebBrowserNavigationEvent newEvent) {
// launch default OS browser
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(new URI(newEvent.getNewResourceLocation()));
} catch (Exception ex) {}
}
}
newEvent.consume();
// immediately close the new swing window
SwingUtilities.invokeLater(new Runnable() {
public void run() {
newBrowser.getWebBrowserWindow().dispose();
}
});
}
});
}
});