HyperlinkListener in JavaFX WebEngine

Solution 1:

Where you have

System.out.println("KLIKNIETO!!!");

replace with

String href = ((Element)ev.getTarget()).getAttribute("href");

to get the URL of the link clicked on.

This page gives a good example of what you are trying to do:

http://blogs.kiyut.com/tonny/2013/07/30/javafx-webview-addhyperlinklistener

Solution 2:

You can catch the link click event by adding a click event handler in Java using the w3c dom classes once the relevant document has loaded.

See Sergey's example in Detecting HTML textarea onkeyup event in JavaFX WebView.

You can also catch the events using JavaScript (for example using jQuery), which might be a little easier to work with than the w3c dom api.

If you are using JavaScript to catch events and you want to feedback notification of the events or subsequent processing from JavaScript to Java, you can use the JavaScript <=> Java bridge api.

I've logged a request to get a sample of this functionality added to the official WebView tutorial.