Community
Participate
Working Groups
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
Thanks for reporting this! The WindowEvent fired in a VisibilityWindowListener.show contains the location of the new window. If your application needs to handle new windows, you should handle all OpenWindowListener/VisibilityWindowListener/CloseWindowListener as indicated in the WindowEvent javadoc.
So Christophe, it sounds like this is working how it is suppose to work and that Ben just has some more work to do to handle some more events. Am I reading this correctly? If so, please resolve this bug report as invalid. If not, please advise on the status of this bug.
Hi Steven, I just tried the snippet again with SWT 3.050 and experienced the same curious behaviour: When calling "event.browser.getUrl();" in OpenWindowListener the target="_blank" link in the index.html causes the IE to open the link into. Having that line commented, nothing happens. Please correct me if I am wrong, but I dont think this behaviour is wanted? Regards, Ben
Steven, this PR is to investigate further the strange IE behaviour demonstrated by Benjamin's snippet when getUrl is called from within OpenWindowListener.open. Comment 2 describes how to actually get the location of the new window. The snippet exhibits an unexpected behaviour. Is this problem blocking you?
It is not blocking me nor the product team that first brought it to my attention. As for Ben and his project, I will leave it to him to evaluate how critical this one is.
Well this problem is not critical for my project, it was never. I just wanted to report this problem to Eclipse, after I've noticed it.
At long last, here is the key to this mystery. . event.browser is null (as defined in the javadoc of OpenWindowListener.open - this field is to be set by the listener) - so it's wrong to access it! .event.browser.getUrl() triggers an NPE. The code should be using ((Browser)event.widget).getUrl() bug 4811 is going to improve the way exceptions are thrown from within DND and OLE callbacks. In that case, it was silently caught deep inside our OLE binding and leaving IE to a default mode of opening the window into a new window.
v>20050126 - setting appropriate default value expected by IE before application code has a chance at throwing exception. Previously, IE would assume the event was not handled and would bring a new instance in while the JVM throws an exception.