我试图根据html文件使用javafx从webview获取所选文本的索引。
我的查询是假设html文件中的stackoverflow索引是200,那么如果我在webview中选择stackoverflow字,那么它应该返回相同的索引200。为了获取所选文本,我使用以下代码
try{
String selection = (String) webView.getEngine()
.executeScript("window.getSelection().toString()");
System.out.println(selection);
}
catch(Exception ex)
{
ex.printStackTrace();
}