久久久久久久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?(如何在電子應用程序中訪問相機/網絡攝像頭?)
主站蜘蛛池模板: 日韩美av | 欧美电影一区 | 久久精品视频免费观看 | 91视频大全 | 亚洲天堂中文字幕 | 成人久久久 | 国产精品99免费视频 | 日韩三级在线观看 | a黄在线观看 | 欧洲一区在线观看 | 国产精品成人一区二区三区 | 欧美 中文字幕 | 精品久久久久久久久久 | 精品视频在线观看 | 亚洲男人的天堂网站 | 天天综合国产 | 国产精品久久久久久久7电影 | 日本涩涩视频 | 成在线人视频免费视频 | 免费观看毛片 | 91久久国产综合久久 | 黄色大片观看 | 中文字幕 欧美 日韩 | 97伦理影院 | 一区二区日韩 | 天堂av中文 | 久久99精品久久久久久 | 国产a区| 久久精品国产久精国产 | 在线欧美亚洲 | 亚洲色图网址 | 国产97色 | 成年人在线观看 | 综合一区二区三区 | 一区二区精品 | 美女天天干 | 91视频进入 | 国产乱码一二三区精品 | 伊人精品一区二区三区 | 国产精品欧美一区喷水 | 亚洲欧美一区二区三区在线 |