Answer the question
In order to leave comments, you need to log in
JavaFX. Is it possible, when working with a WebView, to change the actions that occur when a link is clicked?
Is there some method that is responsible for handling the click on the link?
Answer the question
In order to leave comments, you need to log in
You can get elements from the webview through the DOM model and register handlers on them:
WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();
webEngine.getLoadWorker().stateProperty().addListener(
( ov, oldState, newState) -> {
if (newState == Worker.State.SUCCEEDED) {
// all next classes are from org.w3c.dom domain
org.w3c.dom.events.EventListener listener = ( ev) -> {
System.out.println("#" + ev.getType());
};
org.w3c.dom.Document doc = webEngine.getDocument();
org.w3c.dom.Element el = doc.getElementById("mylink");
((org.w3c.dom.events.EventTarget) el).addEventListener("click", listener, false);
}
});
webEngine.loadContent("<a id='mylink' href='google.com'>hi</a>");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question