开发者

Get URL from Eclipse's internal web browser

I've been having a hard time figuring this one out. I'm writing a plugin in eclipse which launches Eclipse's internal web browser. So far I've 开发者_如何学Pythonopened up the internal web browser:

IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser(IWorkbenchBrowserSupport.LOCATION_BAR, null,"Expert Viewer", "Validation");
browser.openURL(new URL(some url));

and I want to get the url of the current page that is opened in the browser. How do I accomplish that?


The problem with using IWorkbenchBrowserSupport is that you're not guaranteed to get an internal browser back. It may open an external browser if the internal browser is not available, or the workbench is configured to use it, etc.

If you know you always want an internal browser (and that you're only supporting platforms where the internal browser is always available) then you can forego the IWorkbenchBrowserSupport interface and simply use the org.eclipse.swt.browser.Browser widget. Then you can hook up a LocationListener, for example:

Browser browser = new Browser(parent, SWT.NONE);
browser.addLocationListener(new LocationListener() {
    public void changing(LocationEvent event)
    {
        System.out.println("Navigating to: " + event.location);
    }

    public void changed(LocationEvent event)
    {
        System.out.println("Location is: " + event.location);
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜