電子アプリケーションでWebビューから選択したテキストを取得するにはどうすればよいですか? 私はAngular with Electronを使用しています。だから私はWebViewのを持っているコンポーネントがあります。電子メールから選択したテキストを取得
<webview id="foo" attr.src={{activeUrl}} style="height: 600px"></webview>
をこれは私が選択したテキストを取得するために使用するものです。
let rightClickPosition = null;
const menu = new Menu();
const menuItem = new MenuItem({
label: 'Get selected text',
click:() => {
// does not work for selected text in webview
console.log(window.getSelection().toString());
}
});
menu.append(menuItem);
window.addEventListener('contextmenu', (e) => {
e.preventDefault();
rightClickPosition = {x: e.x, y: e.y};
menu.popup(remote.getCurrentWindow());
}, false);
問題:window.getSelection().toString()
で選択したテキストのために動作しません。 webview。これはwebviewの外のテキストに対してのみ機能します。
ありがとうございました!私はここでチュートリアルを見つけました:https://ourcodeworld.com/articles/read/201/how-to-send-retrieve-information-and-manipulate-the-dom-from-a-webview-with-electron-framework – Mate