Reputation: 103
I'm making a simple JavaFX app embedding a WebView. After searching a lot on the internet, I still can't find any solution to detect URL changes while the user is navigating the web.
Is there any method such as the actionPerfomed() method, but for URL changes? Or is there any other way to do it?
Thank you
Upvotes: 0
Views: 1729
Reputation: 6142
Let's say webEngine
is the engine of your WebView. You can detect the URL changes inside the following changed(...)
method:
webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
@Override
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == Worker.State.SUCCEEDED) {
System.out.println(webEngine.getLocation()); //NEW URL
}
}
});
Upvotes: 4