【发布时间】:2018-05-29 02:38:24
【问题描述】:
如何从电子应用程序的 web 视图中获取选定的文本? 我正在使用 Angular 和 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() 不适用于 web 视图中的选定文本。它仅适用于 webview 之外的文本。
【问题讨论】:
标签: javascript angular webview electron