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:
browser.addProgressListener(new ProgressAdapter() {
boolean firstCompleted = false;
@Override
public void completed(ProgressEvent evt) {
if (!firstCompleted) {
String search = "Pictures";
// this row doesn't work... - not yet ;)
int n = (int) browser.evaluate("return str.search(\"" + search + "\"));");
if (n == -1) {
// string not found
} else if(n >= 1) {
// string found
}
firstCompleted = true;
}
}
});
JavaScript should check if the string is available and return the integer n
which includes the result of the str.search()-Operation. If n == -1
there is no such string, if n == 1
the string was found on the website.