1

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>
Gurjeet Singh
  • 43
  • 1
  • 10
  • What's the question? What's going wrong with the code you provided? – jewelsea May 13 '16 at 21:00
  • There might be something going wrong on the JavaScipt side or the Java side. The JS side you can inspect by injecting Firebug (See http://stackoverflow.com/questions/17387981/javafx-webview-webengine-firebuglite-or-some-other-debugger). Please post your findings by updating your question. – hotzst May 14 '16 at 06:09
  • In this code , when i click on button or on link then no java method called – Gurjeet Singh May 14 '16 at 10:08
  • You mentioned PHP though? How does that come in? – Evan Knowles Jun 15 '16 at 08:23

0 Answers0