久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從電子網絡視圖中獲取選定的文本

Get selected text from electron webview(從電子網絡視圖中獲取選定的文本)
本文介紹了從電子網絡視圖中獲取選定的文本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如何從電子應用程序的 web 視圖中獲取選定的文本?我正在使用 Angular 和 Electron.所以我有一個有 webview 的組件:

How to get the selected text from a webview in an electron application? I am using Angular with Electron. So I have a component which has a webview:

<webview id="foo" attr.src={{activeUrl}} style="height: 600px"></webview>

這是我用來獲取選定文本的:

This is what I use for getting the selected text:

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 之外的文本.

The problem: window.getSelection().toString() does not work for the selected text in the webview. It works only for the text outside the webview.

推薦答案

webView 是 Electron 中的一種特殊標簽.作為文檔(https://electronjs.org/docs/api/webview-tag) 說,與 iframe 不同,webview 在與您的應用程序不同的進程中運行.它與您的網頁沒有相同的權限,并且您的應用與嵌入內容之間的所有交互都是異步的..

webView is special kind of tag in Electron. as document (https://electronjs.org/docs/api/webview-tag) says, Unlike an iframe, the webview runs in a separate process than your app. It doesn't have the same permissions as your web page and all interactions between your app and embedded content will be asynchronous..

由于它是不同的過程并且不允許直接交互,因此您可以在 webview 和外框之間使用 ipc 進行通信.檢查 Electron 的 ipc 是否建立.具體來說,您可能對渲染器主機和 web 視圖的 ipcRenderer.sendToHost 感興趣.

Since it's different process and doesn't allow direct interaction, way you can communicate is using ipc between webview and outer frame. Check Electron's ipc to establish. Specifically you may interested in ipcRenderer.sendToHost for renderer host and webview.

這篇關于從電子網絡視圖中獲取選定的文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創建子窗口時如何修復 BrowserWindow 不是構造函數錯誤) - IT屋-程序員軟件開發技術
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 欧美www在线观看 | 日本久久精品 | 女人天堂av | 日韩精品一区二区三区在线播放 | 99久久电影 | 久久精品二区 | 亚洲欧洲激情 | 天天搞天天操 | 久久久久久久综合 | 国产女人精品视频 | 久久在线精品 | 亚洲人成人一区二区在线观看 | 日韩欧美在线一区 | 精品国产成人 | 国产免费观看久久黄av片涩av | 国产一区亚洲二区三区 | 国产一区二区三区四区在线观看 | 亚洲精品中文字幕在线观看 | 欧美日韩网站 | 亚洲免费一区 | 黄色精品 | 日韩欧美久久 | 久久三级影院 | 精品一区久久 | 亚洲91精品 | 天天影视亚洲综合网 | 五月槐花香| 成人在线精品视频 | 在线国产视频 | 91精品国产777在线观看 | 国产精品国产精品 | 国产一区二区麻豆 | 亚洲看片网站 | 亚洲精品视频免费观看 | 成人免费视频网址 | 一二三在线视频 | 日日日干干干 | 日本一本视频 | 精品少妇v888av | 在线国产小视频 | 亚洲午夜在线 |