I'm using an SWT Browser in my Eclipse plug-in project. It shows a browser in a view that displays HTML generated locally. On Mac everything works fine. I can open a local link in the same browser using the code
browser.addOpenWindowListener(new OpenWindowListener() {
public void open(WindowEvent event) {
event.browser = browser;
event.required = true;
}
});
Now I want the same behavior on Windows, but I could never succeed. Nothing happens when I click on the link. And if I remove the listener, an Internet Explorer window opens when I click on the lick, not what I want.
I have seen that in windows the SWT Browser is using an IE style. And I have read posts on how to make Mozilla style Browser in windows. But I don't want users to do any extra setting or install anything else.
Does anyone have a solution?
EDIT: example code to show local html file
String url = "C:\\Users\\myname\\runtime-EclipseApplication\\tt\\target\\Results.html";
try {
URI uri = new File(url).toURI();
URL urls = uri.toURL();
browser.setUrl(urls.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
}
This works just fine here on Windows 7 using a Browser with SWT.NONE:
public static void main(String[] args)
{
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new FillLayout());
Browser browser = new Browser(shell, SWT.NONE);
String url = "start.html";
try
{
URI uri = new File(url).toURI();
URL urls = uri.toURL();
browser.setUrl(urls.toString());
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
shell.pack();
shell.setSize(400, 300);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
This is the content of the start.html:
<a href="./test.html">Click here</a>
And the content of test.html:
<h1>HELLO</h1>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With