Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Launching new browser windows from browser control
Launching new browser windows from browser control [message #431344] Thu, 11 March 2004 01:23 Go to next message
Mike Hoeffner is currently offline Mike HoeffnerFriend
Messages: 3
Registered: July 2009
Junior Member
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 15:25 Go to previous messageGo to next message
Michal Tkacz is currently offline Michal TkaczFriend
Messages: 105
Registered: July 2009
Senior Member
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 14:38 Go to previous message
Christophe Cornu is currently offline Christophe CornuFriend
Messages: 304
Registered: July 2009
Senior Member
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 Apr 24 23:31:13 GMT 2024

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

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

Back to the top