0

I do have an application containing JavaFX webview. Within the application I am generating a html page and it gets displayed. Now, if the user clicks or selects text I would like to get the corresponding HTML code of the selection. Is that even possible?

Thank you!

1 Answers1

0

Sure, you need to handle selection and click events in your web page with JavaScript, i.e. with jQuery and in your event handler function to call you Java method handler. Here is an example of JS-to-Java call - Communicating between JavaScript and JavaFX with WebEngine. This will basically provide a Java object inside a WebView:

JSObject jsobj = (JSObject) webEngine.executeScript("window");
jsobj.setMember("javaBridge", new Bridge());

And this is how it can be accessed from a WebView:

<a href="" onclick="javaBridge.exit();">here</a>
Andrey Chaschev
  • 16,160
  • 5
  • 51
  • 68
  • Thank you so much for your fast reply. The JS approach is great and works fine for me. I did the following: - added some JS/Jquery code to my html file (which basically just sets onclick handlers for certain tags) - the functions called after onclick just alert the values I am interested in - on the Java side I have used the setOnAlert Method to define an EventHandler which listens for alerts. Again, thank you! – user3069486 Dec 06 '13 at 10:40
  • You're welcome! Just in case you need better debugging inside a WebView, have a look at this answer: http://stackoverflow.com/questions/17387981/javafx-webview-webengine-firebuglite-or-some-other-debugger. – Andrey Chaschev Dec 06 '13 at 11:24