I tried different solution to make my webview point to a specific anchor in the document but failed.
my target name is 'occ'
I used window.location.hash = 'occ'
and window.location.href ='#occ'
but didn't work here my code
contentView.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
public void changed(@SuppressWarnings("rawtypes") ObservableValue ov, State oldState, State newState) {
if (newState == State.SUCCEEDED) {
System.out.println("loaded");
doc = contentView.getEngine().getDocument();
JSObject windowObject = (JSObject) contentView.getEngine().executeScript("window");
windowObject.call("scrollTo", 0, 600);//this works
contentView.getEngine().executeScript("location.hash = 'occ'"); // doesn't work
windowObject.call("location.hash", "occ"); // doesn't work
}
}
});
here the part of the code where i create anchor
org.jsoup.nodes.Document d = Jsoup.parse(new File(doc.get("path")), "utf-8");
String searchedPage = d.toString();
for (String keyword : keywordsArray) {
searchedPage = searchedPage.replaceAll(keyword,
"<a id='occ' name='occ'><span style='font-weight:bold; background:yellow'>" + keyword + "</span></a>");
}
contentEngine.loadContent(searchedPage);