Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Launching new browser windows from browser control
Launching new browser windows from browser control [message #431344] Wed, 10 March 2004 20:23 Go to next message
Eclipse UserFriend
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
Re: Launching new browser windows from browser control [message #431978 is a reply to message #431344] Fri, 12 March 2004 10:25 Go to previous messageGo to next message
Eclipse UserFriend
Hi Mike,

As far as I know, you'll have to create the windows yourself by adding
an instance of OpenWindowListener to your browser using
addOpenWindowListener method.

Check the javadoc for org.eclipse.swt.browser.WindowEvent for examples.

Michal Tkacz


User Mike Hoeffner wrote:
> 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
>
>
Re: Launching new browser windows from browser control [message #432040 is a reply to message #431978] Mon, 15 March 2004 09:38 Go to previous message
Eclipse UserFriend
In addition, you can see how the WindowEvents are used in the
BrowserExample, which is part of the Example Plug-ins available from the
eclipse download page.

Chris
Previous Topic:Almost able to get composite to work in Table
Next Topic:Table with 2 checkboxes per row
Goto Forum:
  


Current Time: Wed Jul 16 05:49:01 EDT 2025

Powered by FUDForum. Page generated in 0.89578 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top