Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to getSelectedText from webView in javaFX

I need to get the selected text from webView in javaFX. I have not found any clue how to do it on the internet.

like image 237
Kaa Avatar asked Oct 08 '12 16:10

Kaa


1 Answers

This can be done with JavaScript:

String selection = (String) webView.getEngine()
                     .executeScript("window.getSelection().toString()");
System.out.println(selection);

Also you may find this helpful:
Communicating between JavaScript and JavaFX with WebEngine
executeScript

like image 164
Someone Avatar answered Sep 18 '22 23:09

Someone