0

As noted above, once the user clicks on something that changes the page, the scripting using JavaFX no longer works.

hello.html

<div onclick="app.byeBye()">bye</div>

byebye.html

<div onclick="app.hello()">hello</div>

JavaApp.class

 public class JavaApp{

    public void hello(){
        //process some stuff here
        setURL("/hello.html");
    }

    public void byeBye(){
        //process some stuff here
        setURL("/byebye.html");
    }

    private void setURL(final String uriString){
       Platform.runLater(new Runnable(){

            public void run(){
                JSObject win = (JSObject) webViewPanel.getWebEngine().executeScript("window");
                win.setMember("app",  new JavaApp());
                webViewPanel.loadURL(Browser.class.getResource(uriString).toExternalForm());
            }
        });
    }
}

What must I do to fix this problem?

theAnonymous
  • 1,701
  • 2
  • 28
  • 62
  • 1
    Try to get the window object and set "app" after webview's engine loads the url successfully. Namely when the engine's state is State.SUCCEEDED. See WebEngine's javadoc. – Uluk Biy Sep 01 '14 at 07:10

1 Answers1

0

Answer by Uluk Biy is correct (but I can not make a comment an answer). Be sure to thumb him up if this is helpful.

Try to get the window object and set "app" after webview's engine loads the url successfully. Namely when the engine's state is State.SUCCEEDED. See WebEngine's javadoc.

The WebEngine API page is here: http://docs.oracle.com/javafx/2/api/javafx/scene/web/WebEngine.html

theAnonymous
  • 1,701
  • 2
  • 28
  • 62