Skip to content Skip to sidebar Skip to footer

Search String In Swt Webbrowser Widget

I wrote a program which includes the browser widget from swt. Now I navigate to google and want to search for the string 'Pictures' for example. This is my code but it doesn't work

Solution 1:

Here is a very simple example, that will return a value from JavaScript to Java and print it to the command line:

publicstaticvoidmain(String[] args)
{
    Displaydisplay=newDisplay();
    finalShellshell=newShell(display);
    shell.setText("StackOverflow");
    shell.setLayout(newFillLayout());

    finalBrowserbrowser=newBrowser(shell, SWT.NONE);
    browser.setText("......baz");

    Buttonb=newButton(shell, SWT.PUSH);
    b.setText("Do something");
    b.addListener(SWT.Selection, newListener()
    {
        publicvoidhandleEvent(Event e)
        {
            Stringbaz="baz";
            booleanresult= (boolean) browser.evaluate("return window.find('" + baz + "');");
            System.out.println(result);
        }
    });

    shell.pack();
    shell.open();
    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

Note that I used a different JS function than you did and that you have an additional closing bracket in your JS code.

Here is an excellent tutorial.

Post a Comment for "Search String In Swt Webbrowser Widget"