Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のコード スニペットで、選択したテキストを取得できます。 String selection = (String) webView.getEngine().executeScript("window.getSelection().toString()"); System.out.println(選択);
しかし、domツリーにコンテンツを追加したいので、選択したノードを取得する方法はありますか?
executeScript は JavaScript のみを実行し、スクリプトが返すものは何でも返すため、これはより JavaScript に関する質問です。やってみます
document.getSelection().getRangeAt(0).commonAncestorContainer.parentNode
これは、選択されたパーツを生成するコンテナーの親ノードを返します。