I have a javaFx application in this am loading a web php page on the webview , in this php page there is a PRINT button , on click of this print button am calling a javascript method , now am trying to call java method from this javascript via javaScript objrct.
am referring this link:- http://knowles.co.za/javafx-and-javascript-calling-java-from-javascript/
This this my java code: `
class Bridge {
public void callJava() {
System.err.println(" javaScript javaScript javaScript javaScript javaScript javaScript");
}
public void printId(Object object) {
if (org.w3c.dom.html.HTMLElement.class.isAssignableFrom(object.getClass())) {
org.w3c.dom.html.HTMLElement it = (org.w3c.dom.html.HTMLElement) object;
System.out.println("Id is " + it.getId());
}
}
}
`
This java code is calling on loading the url:
we.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
@Override
public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
if (newValue == Worker.State.SUCCEEDED) {
JSObject window = (JSObject) we.executeScript("window");
window.setMember("app", new Bridge());
}
}
}
And this is on server php page:-
<div align="center">
<br>
<button id="print_btn" name="print_btn" onClick="callJava1()" style="width:100px; height:40px;">Print</button>
<br>
<a onClick="me()" href="#">Print</a>
<script>
function me(){
app.printId("abc");
}
</script>
<br><br>
<br>
</div>