Launching new browser windows from browser control [message #431344] |
Wed, 10 March 2004 20:23  |
Eclipse User |
|
|
|
Is there a trick to enabling the browser control to create new windows
when a clicked link contains a blank target or when the JavaScript method
window.open() is called?
Below is a complete code snippet that demonstrates the problem. The first
link works. The second and third appear to be ignored.
---
import org.eclipse.swt.*;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class Main
{
public static void main(String [] args)
{
/*
<html><head></head><body>
<a href="http://www.yahoo.com">Yahoo (normal link)</a><br>
<a href="http://www.yahoo.com" target="_blank">Yahoo (link with
blank target)</a><br>
<a href="" onClick="window.open('http://www.yahoo.com');return
false;">Yahoo (JavaScript window.open)</a>
</body></html>
*/
String html = "<html><head></head><body>";
html += "<a href=\"http://www.yahoo.com\">Yahoo (normal
link)</a><br>";
html += "<a href=\"http://www.yahoo.com\" target=\"_blank\">Yahoo
(link with blank target)</a><br>";
html += "<a href=\"\"
onClick=\"window.open('http://www.yahoo.com');return false;\">Yahoo
(JavaScript window.open)</a>";
html += "</body></html>";
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Browser browser = new Browser(shell, SWT.NONE);
browser.setText(html);
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
}
---
Thanks for any help!
Mike
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.89578 seconds