Project: SWT
Bug 57068 [browser] Curious behaviour on target=_blank links
Reported: 2004-04-01 13:21:01 | Status: resolved fixed

Hi, I am using the SWT browser widget to display HTML and let the user navigate through the WWW in my application. Earlier the browser ignored clicking on links that would open in a new window (with having target="_blank"). I've now found out the OpenWindowListener which could solve my problem. Playing around with it, I came up to this snippet, which shows a very strange behaviour: public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("Main Window"); shell.setLayout(new FillLayout()); Browser browser = new Browser(shell, SWT.NONE); initialize(display, browser); shell.open(); browser.setUrl("C:/index.html"); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } static void initialize(final Display display, Browser browser) { browser.addOpenWindowListener(new OpenWindowListener() { public void open(WindowEvent event) { event.browser.getUrl(); //Comment / Uncomment this line! } }); } The file "index.html" is a local HTML file with a simple link that uses target="_blank". Having the "event.browser.getUrl();" commented, nothing happens. But when uncommented, after clicking on the URL it opens in my system default browser (IE). I am also wondering, why the WindowEvent event does not provide information about the URL that the new browser-window will load? Regards, Ben

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Browser.java